ipmi_si_sm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * ipmi_si_sm.h
  4. *
  5. * State machine interface for low-level IPMI system management
  6. * interface state machines. This code is the interface between
  7. * the ipmi_smi code (that handles the policy of a KCS, SMIC, or
  8. * BT interface) and the actual low-level state machine.
  9. *
  10. * Author: MontaVista Software, Inc.
  11. * Corey Minyard <minyard@mvista.com>
  12. * source@mvista.com
  13. *
  14. * Copyright 2002 MontaVista Software Inc.
  15. */
  16. #include <linux/ipmi.h>
  17. /*
  18. * This is defined by the state machines themselves, it is an opaque
  19. * data type for them to use.
  20. */
  21. struct si_sm_data;
  22. enum si_type {
  23. SI_TYPE_INVALID, SI_KCS, SI_SMIC, SI_BT
  24. };
  25. /*
  26. * The structure for doing I/O in the state machine. The state
  27. * machine doesn't have the actual I/O routines, they are done through
  28. * this interface.
  29. */
  30. struct si_sm_io {
  31. unsigned char (*inputb)(const struct si_sm_io *io, unsigned int offset);
  32. void (*outputb)(const struct si_sm_io *io,
  33. unsigned int offset,
  34. unsigned char b);
  35. /*
  36. * Generic info used by the actual handling routines, the
  37. * state machine shouldn't touch these.
  38. */
  39. void __iomem *addr;
  40. int regspacing;
  41. int regsize;
  42. int regshift;
  43. int addr_type;
  44. long addr_data;
  45. enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */
  46. void (*addr_source_cleanup)(struct si_sm_io *io);
  47. void *addr_source_data;
  48. union ipmi_smi_info_union addr_info;
  49. int (*io_setup)(struct si_sm_io *info);
  50. void (*io_cleanup)(struct si_sm_io *info);
  51. unsigned int io_size;
  52. int irq;
  53. int (*irq_setup)(struct si_sm_io *io);
  54. void *irq_handler_data;
  55. void (*irq_cleanup)(struct si_sm_io *io);
  56. u8 slave_addr;
  57. enum si_type si_type;
  58. struct device *dev;
  59. };
  60. /* Results of SMI events. */
  61. enum si_sm_result {
  62. SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
  63. SI_SM_CALL_WITH_DELAY, /* Delay some before calling again. */
  64. SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
  65. SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
  66. SI_SM_IDLE, /* The SM is in idle state. */
  67. SI_SM_HOSED, /* The hardware violated the state machine. */
  68. /*
  69. * The hardware is asserting attn and the state machine is
  70. * idle.
  71. */
  72. SI_SM_ATTN
  73. };
  74. /* Handlers for the SMI state machine. */
  75. struct si_sm_handlers {
  76. /*
  77. * Put the version number of the state machine here so the
  78. * upper layer can print it.
  79. */
  80. char *version;
  81. /*
  82. * Initialize the data and return the amount of I/O space to
  83. * reserve for the space.
  84. */
  85. unsigned int (*init_data)(struct si_sm_data *smi,
  86. struct si_sm_io *io);
  87. /*
  88. * Start a new transaction in the state machine. This will
  89. * return -2 if the state machine is not idle, -1 if the size
  90. * is invalid (to large or too small), or 0 if the transaction
  91. * is successfully completed.
  92. */
  93. int (*start_transaction)(struct si_sm_data *smi,
  94. unsigned char *data, unsigned int size);
  95. /*
  96. * Return the results after the transaction. This will return
  97. * -1 if the buffer is too small, zero if no transaction is
  98. * present, or the actual length of the result data.
  99. */
  100. int (*get_result)(struct si_sm_data *smi,
  101. unsigned char *data, unsigned int length);
  102. /*
  103. * Call this periodically (for a polled interface) or upon
  104. * receiving an interrupt (for a interrupt-driven interface).
  105. * If interrupt driven, you should probably poll this
  106. * periodically when not in idle state. This should be called
  107. * with the time that passed since the last call, if it is
  108. * significant. Time is in microseconds.
  109. */
  110. enum si_sm_result (*event)(struct si_sm_data *smi, long time);
  111. /*
  112. * Attempt to detect an SMI. Returns 0 on success or nonzero
  113. * on failure.
  114. */
  115. int (*detect)(struct si_sm_data *smi);
  116. /* The interface is shutting down, so clean it up. */
  117. void (*cleanup)(struct si_sm_data *smi);
  118. /* Return the size of the SMI structure in bytes. */
  119. int (*size)(void);
  120. };
  121. /* Current state machines that we can use. */
  122. extern const struct si_sm_handlers kcs_smi_handlers;
  123. extern const struct si_sm_handlers smic_smi_handlers;
  124. extern const struct si_sm_handlers bt_smi_handlers;