acpiphp.h 4.6 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 (greg@kroah.com)
  7. * Copyright (C) 2001 IBM Corp.
  8. * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
  9. * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
  10. * Copyright (C) 2002,2003 NEC Corporation
  11. * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
  12. * Copyright (C) 2003-2005 Hewlett Packard
  13. *
  14. * All rights reserved.
  15. *
  16. * Send feedback to <gregkh@us.ibm.com>,
  17. * <t-kochi@bq.jp.nec.com>
  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. struct hotplug_slot_info info;
  35. unsigned int sun; /* ACPI _SUN (Slot User Number) value */
  36. };
  37. static inline const char *slot_name(struct slot *slot)
  38. {
  39. return hotplug_slot_name(slot->hotplug_slot);
  40. }
  41. /*
  42. * struct acpiphp_bridge - PCI bridge information
  43. *
  44. * for each bridge device in ACPI namespace
  45. */
  46. struct acpiphp_bridge {
  47. struct list_head list;
  48. struct list_head slots;
  49. struct kref ref;
  50. struct acpiphp_context *context;
  51. int nr_slots;
  52. /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
  53. struct pci_bus *pci_bus;
  54. /* PCI-to-PCI bridge device */
  55. struct pci_dev *pci_dev;
  56. bool is_going_away;
  57. };
  58. /*
  59. * struct acpiphp_slot - PCI slot information
  60. *
  61. * PCI slot information for each *physical* PCI slot
  62. */
  63. struct acpiphp_slot {
  64. struct list_head node;
  65. struct pci_bus *bus;
  66. struct list_head funcs; /* one slot may have different
  67. objects (i.e. for each function) */
  68. struct slot *slot;
  69. u8 device; /* pci device# */
  70. u32 flags; /* see below */
  71. };
  72. /*
  73. * struct acpiphp_func - PCI function information
  74. *
  75. * PCI function information for each object in ACPI namespace
  76. * typically 8 objects per slot (i.e. for each PCI function)
  77. */
  78. struct acpiphp_func {
  79. struct acpiphp_bridge *parent;
  80. struct acpiphp_slot *slot;
  81. struct list_head sibling;
  82. u8 function; /* pci function# */
  83. u32 flags; /* see below */
  84. };
  85. struct acpiphp_context {
  86. struct acpi_hotplug_context hp;
  87. struct acpiphp_func func;
  88. struct acpiphp_bridge *bridge;
  89. unsigned int refcount;
  90. };
  91. static inline struct acpiphp_context *to_acpiphp_context(struct acpi_hotplug_context *hp)
  92. {
  93. return container_of(hp, struct acpiphp_context, hp);
  94. }
  95. static inline struct acpiphp_context *func_to_context(struct acpiphp_func *func)
  96. {
  97. return container_of(func, struct acpiphp_context, func);
  98. }
  99. static inline struct acpi_device *func_to_acpi_device(struct acpiphp_func *func)
  100. {
  101. return func_to_context(func)->hp.self;
  102. }
  103. static inline acpi_handle func_to_handle(struct acpiphp_func *func)
  104. {
  105. return func_to_acpi_device(func)->handle;
  106. }
  107. struct acpiphp_root_context {
  108. struct acpi_hotplug_context hp;
  109. struct acpiphp_bridge *root_bridge;
  110. };
  111. static inline struct acpiphp_root_context *to_acpiphp_root_context(struct acpi_hotplug_context *hp)
  112. {
  113. return container_of(hp, struct acpiphp_root_context, hp);
  114. }
  115. /*
  116. * struct acpiphp_attention_info - device specific attention registration
  117. *
  118. * ACPI has no generic method of setting/getting attention status
  119. * this allows for device specific driver registration
  120. */
  121. struct acpiphp_attention_info
  122. {
  123. int (*set_attn)(struct hotplug_slot *slot, u8 status);
  124. int (*get_attn)(struct hotplug_slot *slot, u8 *status);
  125. struct module *owner;
  126. };
  127. /* ACPI _STA method value (ignore bit 4; battery present) */
  128. #define ACPI_STA_ALL (0x0000000f)
  129. /* slot flags */
  130. #define SLOT_ENABLED (0x00000001)
  131. #define SLOT_IS_GOING_AWAY (0x00000002)
  132. /* function flags */
  133. #define FUNC_HAS_STA (0x00000001)
  134. #define FUNC_HAS_EJ0 (0x00000002)
  135. /* function prototypes */
  136. /* acpiphp_core.c */
  137. int acpiphp_register_attention(struct acpiphp_attention_info *info);
  138. int acpiphp_unregister_attention(struct acpiphp_attention_info *info);
  139. int acpiphp_register_hotplug_slot(struct acpiphp_slot *slot, unsigned int sun);
  140. void acpiphp_unregister_hotplug_slot(struct acpiphp_slot *slot);
  141. /* acpiphp_glue.c */
  142. typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
  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 */