pci_hotplug.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * PCI HotPlug Core Functions
  4. *
  5. * Copyright (C) 1995,2001 Compaq Computer Corporation
  6. * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
  7. * Copyright (C) 2001 IBM Corp.
  8. *
  9. * All rights reserved.
  10. *
  11. * Send feedback to <kristen.c.accardi@intel.com>
  12. *
  13. */
  14. #ifndef _PCI_HOTPLUG_H
  15. #define _PCI_HOTPLUG_H
  16. /**
  17. * struct hotplug_slot_ops -the callbacks that the hotplug pci core can use
  18. * @owner: The module owner of this structure
  19. * @mod_name: The module name (KBUILD_MODNAME) of this structure
  20. * @enable_slot: Called when the user wants to enable a specific pci slot
  21. * @disable_slot: Called when the user wants to disable a specific pci slot
  22. * @set_attention_status: Called to set the specific slot's attention LED to
  23. * the specified value
  24. * @hardware_test: Called to run a specified hardware test on the specified
  25. * slot.
  26. * @get_power_status: Called to get the current power status of a slot.
  27. * If this field is NULL, the value passed in the struct hotplug_slot_info
  28. * will be used when this value is requested by a user.
  29. * @get_attention_status: Called to get the current attention status of a slot.
  30. * If this field is NULL, the value passed in the struct hotplug_slot_info
  31. * will be used when this value is requested by a user.
  32. * @get_latch_status: Called to get the current latch status of a slot.
  33. * If this field is NULL, the value passed in the struct hotplug_slot_info
  34. * will be used when this value is requested by a user.
  35. * @get_adapter_status: Called to get see if an adapter is present in the slot or not.
  36. * If this field is NULL, the value passed in the struct hotplug_slot_info
  37. * will be used when this value is requested by a user.
  38. * @reset_slot: Optional interface to allow override of a bus reset for the
  39. * slot for cases where a secondary bus reset can result in spurious
  40. * hotplug events or where a slot can be reset independent of the bus.
  41. *
  42. * The table of function pointers that is passed to the hotplug pci core by a
  43. * hotplug pci driver. These functions are called by the hotplug pci core when
  44. * the user wants to do something to a specific slot (query it for information,
  45. * set an LED, enable / disable power, etc.)
  46. */
  47. struct hotplug_slot_ops {
  48. struct module *owner;
  49. const char *mod_name;
  50. int (*enable_slot) (struct hotplug_slot *slot);
  51. int (*disable_slot) (struct hotplug_slot *slot);
  52. int (*set_attention_status) (struct hotplug_slot *slot, u8 value);
  53. int (*hardware_test) (struct hotplug_slot *slot, u32 value);
  54. int (*get_power_status) (struct hotplug_slot *slot, u8 *value);
  55. int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
  56. int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
  57. int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
  58. int (*reset_slot) (struct hotplug_slot *slot, int probe);
  59. };
  60. /**
  61. * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
  62. * @power_status: if power is enabled or not (1/0)
  63. * @attention_status: if the attention light is enabled or not (1/0)
  64. * @latch_status: if the latch (if any) is open or closed (1/0)
  65. * @adapter_status: if there is a pci board present in the slot or not (1/0)
  66. *
  67. * Used to notify the hotplug pci core of the status of a specific slot.
  68. */
  69. struct hotplug_slot_info {
  70. u8 power_status;
  71. u8 attention_status;
  72. u8 latch_status;
  73. u8 adapter_status;
  74. };
  75. /**
  76. * struct hotplug_slot - used to register a physical slot with the hotplug pci core
  77. * @ops: pointer to the &struct hotplug_slot_ops to be used for this slot
  78. * @info: pointer to the &struct hotplug_slot_info for the initial values for
  79. * this slot.
  80. * @release: called during pci_hp_deregister to free memory allocated in a
  81. * hotplug_slot structure.
  82. * @private: used by the hotplug pci controller driver to store whatever it
  83. * needs.
  84. */
  85. struct hotplug_slot {
  86. struct hotplug_slot_ops *ops;
  87. struct hotplug_slot_info *info;
  88. void (*release) (struct hotplug_slot *slot);
  89. void *private;
  90. /* Variables below this are for use only by the hotplug pci core. */
  91. struct list_head slot_list;
  92. struct pci_slot *pci_slot;
  93. };
  94. static inline const char *hotplug_slot_name(const struct hotplug_slot *slot)
  95. {
  96. return pci_slot_name(slot->pci_slot);
  97. }
  98. int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *pbus, int nr,
  99. const char *name, struct module *owner,
  100. const char *mod_name);
  101. int pci_hp_deregister(struct hotplug_slot *slot);
  102. int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
  103. struct hotplug_slot_info *info);
  104. /* use a define to avoid include chaining to get THIS_MODULE & friends */
  105. #define pci_hp_register(slot, pbus, devnr, name) \
  106. __pci_hp_register(slot, pbus, devnr, name, THIS_MODULE, KBUILD_MODNAME)
  107. /* PCI Setting Record (Type 0) */
  108. struct hpp_type0 {
  109. u32 revision;
  110. u8 cache_line_size;
  111. u8 latency_timer;
  112. u8 enable_serr;
  113. u8 enable_perr;
  114. };
  115. /* PCI-X Setting Record (Type 1) */
  116. struct hpp_type1 {
  117. u32 revision;
  118. u8 max_mem_read;
  119. u8 avg_max_split;
  120. u16 tot_max_split;
  121. };
  122. /* PCI Express Setting Record (Type 2) */
  123. struct hpp_type2 {
  124. u32 revision;
  125. u32 unc_err_mask_and;
  126. u32 unc_err_mask_or;
  127. u32 unc_err_sever_and;
  128. u32 unc_err_sever_or;
  129. u32 cor_err_mask_and;
  130. u32 cor_err_mask_or;
  131. u32 adv_err_cap_and;
  132. u32 adv_err_cap_or;
  133. u16 pci_exp_devctl_and;
  134. u16 pci_exp_devctl_or;
  135. u16 pci_exp_lnkctl_and;
  136. u16 pci_exp_lnkctl_or;
  137. u32 sec_unc_err_sever_and;
  138. u32 sec_unc_err_sever_or;
  139. u32 sec_unc_err_mask_and;
  140. u32 sec_unc_err_mask_or;
  141. };
  142. struct hotplug_params {
  143. struct hpp_type0 *t0; /* Type0: NULL if not available */
  144. struct hpp_type1 *t1; /* Type1: NULL if not available */
  145. struct hpp_type2 *t2; /* Type2: NULL if not available */
  146. struct hpp_type0 type0_data;
  147. struct hpp_type1 type1_data;
  148. struct hpp_type2 type2_data;
  149. };
  150. #ifdef CONFIG_ACPI
  151. #include <linux/acpi.h>
  152. int pci_get_hp_params(struct pci_dev *dev, struct hotplug_params *hpp);
  153. bool pciehp_is_native(struct pci_dev *pdev);
  154. int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags);
  155. int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle);
  156. int acpi_pci_detect_ejectable(acpi_handle handle);
  157. #else
  158. static inline int pci_get_hp_params(struct pci_dev *dev,
  159. struct hotplug_params *hpp)
  160. {
  161. return -ENODEV;
  162. }
  163. static inline bool pciehp_is_native(struct pci_dev *pdev) { return true; }
  164. #endif
  165. #endif