acpiphp.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * ACPI PCI Hot Plug Controller Driver
  4. *
  5. * Copyright (C) 1995,2001 Compaq Computer Corporation
  6. * Copyright (C) 2001 Greg Kroah-Hartman ([email protected])
  7. * Copyright (C) 2001 IBM Corp.
  8. * Copyright (C) 2002 Hiroshi Aono ([email protected])
  9. * Copyright (C) 2002,2003 Takayoshi Kochi ([email protected])
  10. * Copyright (C) 2002,2003 NEC Corporation
  11. * Copyright (C) 2003-2005 Matthew Wilcox ([email protected])
  12. * Copyright (C) 2003-2005 Hewlett Packard
  13. *
  14. * All rights reserved.
  15. *
  16. * Send feedback to <[email protected]>,
  17. * <[email protected]>
  18. *
  19. */
  20. #ifndef _ACPIPHP_H
  21. #define _ACPIPHP_H
  22. #include <linux/acpi.h>
  23. #include <linux/mutex.h>
  24. #include <linux/pci_hotplug.h>
  25. struct acpiphp_context;
  26. struct acpiphp_bridge;
  27. struct acpiphp_slot;
  28. /*
  29. * struct slot - slot information for each *physical* slot
  30. */
  31. struct slot {
  32. struct hotplug_slot hotplug_slot;
  33. struct acpiphp_slot *acpi_slot;
  34. unsigned int sun; /* ACPI _SUN (Slot User Number) value */
  35. };
  36. static inline const char *slot_name(struct slot *slot)
  37. {
  38. return hotplug_slot_name(&slot->hotplug_slot);
  39. }
  40. static inline struct slot *to_slot(struct hotplug_slot *hotplug_slot)
  41. {
  42. return container_of(hotplug_slot, struct slot, hotplug_slot);
  43. }
  44. /*
  45. * struct acpiphp_bridge - PCI bridge information
  46. *
  47. * for each bridge device in ACPI namespace
  48. */
  49. struct acpiphp_bridge {
  50. struct list_head list;
  51. struct list_head slots;
  52. struct kref ref;
  53. struct acpiphp_context *context;
  54. int nr_slots;
  55. /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
  56. struct pci_bus *pci_bus;
  57. /* PCI-to-PCI bridge device */
  58. struct pci_dev *pci_dev;
  59. bool is_going_away;
  60. };
  61. /*
  62. * struct acpiphp_slot - PCI slot information
  63. *
  64. * PCI slot information for each *physical* PCI slot
  65. */
  66. struct acpiphp_slot {
  67. struct list_head node;
  68. struct pci_bus *bus;
  69. struct list_head funcs; /* one slot may have different
  70. objects (i.e. for each function) */
  71. struct slot *slot;
  72. u8 device; /* pci device# */
  73. u32 flags; /* see below */
  74. };
  75. /*
  76. * struct acpiphp_func - PCI function information
  77. *
  78. * PCI function information for each object in ACPI namespace
  79. * typically 8 objects per slot (i.e. for each PCI function)
  80. */
  81. struct acpiphp_func {
  82. struct acpiphp_bridge *parent;
  83. struct acpiphp_slot *slot;
  84. struct list_head sibling;
  85. u8 function; /* pci function# */
  86. u32 flags; /* see below */
  87. };
  88. struct acpiphp_context {
  89. struct acpi_hotplug_context hp;
  90. struct acpiphp_func func;
  91. struct acpiphp_bridge *bridge;
  92. unsigned int refcount;
  93. };
  94. static inline struct acpiphp_context *to_acpiphp_context(struct acpi_hotplug_context *hp)
  95. {
  96. return container_of(hp, struct acpiphp_context, hp);
  97. }
  98. static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func)
  99. {
  100. return container_of(func, struct acpiphp_context, func);
  101. }
  102. static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func)
  103. {
  104. return func_to_context(func)->hp.self;
  105. }
  106. static inline acpi_handle func_to_handle(struct acpiphp_func *func)
  107. {
  108. return func_to_acpi_device(func)->handle;
  109. }
  110. struct acpiphp_root_context {
  111. struct acpi_hotplug_context hp;
  112. struct acpiphp_bridge *root_bridge;
  113. };
  114. static inline struct acpiphp_root_context *to_acpiphp_root_context(struct acpi_hotplug_context *hp)
  115. {
  116. return container_of(hp, struct acpiphp_root_context, hp);
  117. }
  118. /*
  119. * struct acpiphp_attention_info - device specific attention registration
  120. *
  121. * ACPI has no generic method of setting/getting attention status
  122. * this allows for device specific driver registration
  123. */
  124. struct acpiphp_attention_info {
  125. int (*set_attn)(struct hotplug_slot *slot, u8 status);
  126. int (*get_attn)(struct hotplug_slot *slot, u8 *status);
  127. struct module *owner;
  128. };
  129. /* ACPI _STA method value (ignore bit 4; battery present) */
  130. #define ACPI_STA_ALL (0x0000000f)
  131. /* slot flags */
  132. #define SLOT_ENABLED (0x00000001)
  133. #define SLOT_IS_GOING_AWAY (0x00000002)
  134. /* function flags */
  135. #define FUNC_HAS_STA (0x00000001)
  136. #define FUNC_HAS_EJ0 (0x00000002)
  137. /* function prototypes */
  138. /* acpiphp_core.c */
  139. int acpiphp_register_attention(struct acpiphp_attention_info *info);
  140. int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
  141. int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot, unsigned int sun);
  142. void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot);
  143. int acpiphp_enable_slot(struct acpiphp_slot *slot);
  144. int acpiphp_disable_slot(struct acpiphp_slot *slot);
  145. u8 acpiphp_get_power_status(struct acpiphp_slot *slot);
  146. u8 acpiphp_get_attention_status(struct acpiphp_slot *slot);
  147. u8 acpiphp_get_latch_status(struct acpiphp_slot *slot);
  148. u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot);
  149. /* variables */
  150. extern bool acpiphp_disabled;
  151. #endif /* _ACPIPHP_H */