pciehp.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * PCI Express Hot Plug Controller Driver
  3. *
  4. * Copyright (C) 1995,2001 Compaq Computer Corporation
  5. * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
  6. * Copyright (C) 2001 IBM Corp.
  7. * Copyright (C) 2003-2004 Intel Corporation
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  19. * NON INFRINGEMENT. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. *
  26. * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
  27. *
  28. */
  29. #ifndef _PCIEHP_H
  30. #define _PCIEHP_H
  31. #include <linux/types.h>
  32. #include <linux/pci.h>
  33. #include <linux/pci_hotplug.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h> /* signal_pending() */
  36. #include <linux/pcieport_if.h>
  37. #include <linux/mutex.h>
  38. #define MY_NAME "pciehp"
  39. extern int pciehp_poll_mode;
  40. extern int pciehp_poll_time;
  41. extern int pciehp_debug;
  42. extern int pciehp_force;
  43. /*#define dbg(format, arg...) do { if (pciehp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/
  44. #define dbg(format, arg...) do { if (pciehp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0)
  45. #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
  46. #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
  47. #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
  48. #define SLOT_NAME_SIZE 10
  49. struct slot {
  50. u8 bus;
  51. u8 device;
  52. u32 number;
  53. u8 state;
  54. struct timer_list task_event;
  55. u8 hp_slot;
  56. struct controller *ctrl;
  57. struct hpc_ops *hpc_ops;
  58. struct hotplug_slot *hotplug_slot;
  59. struct list_head slot_list;
  60. char name[SLOT_NAME_SIZE];
  61. };
  62. struct event_info {
  63. u32 event_type;
  64. u8 hp_slot;
  65. };
  66. #define MAX_EVENTS 10
  67. struct controller {
  68. struct controller *next;
  69. struct mutex crit_sect; /* critical section mutex */
  70. struct mutex ctrl_lock; /* controller lock */
  71. int num_slots; /* Number of slots on ctlr */
  72. int slot_num_inc; /* 1 or -1 */
  73. struct pci_dev *pci_dev;
  74. struct list_head slot_list;
  75. struct event_info event_queue[MAX_EVENTS];
  76. struct slot *slot;
  77. struct hpc_ops *hpc_ops;
  78. wait_queue_head_t queue; /* sleep & wake process */
  79. u8 next_event;
  80. u8 bus;
  81. u8 device;
  82. u8 function;
  83. u8 slot_device_offset;
  84. u32 first_slot; /* First physical slot number */ /* PCIE only has 1 slot */
  85. u8 slot_bus; /* Bus where the slots handled by this controller sit */
  86. u8 ctrlcap;
  87. u16 vendor_id;
  88. u8 cap_base;
  89. struct timer_list poll_timer;
  90. };
  91. #define INT_BUTTON_IGNORE 0
  92. #define INT_PRESENCE_ON 1
  93. #define INT_PRESENCE_OFF 2
  94. #define INT_SWITCH_CLOSE 3
  95. #define INT_SWITCH_OPEN 4
  96. #define INT_POWER_FAULT 5
  97. #define INT_POWER_FAULT_CLEAR 6
  98. #define INT_BUTTON_PRESS 7
  99. #define INT_BUTTON_RELEASE 8
  100. #define INT_BUTTON_CANCEL 9
  101. #define STATIC_STATE 0
  102. #define BLINKINGON_STATE 1
  103. #define BLINKINGOFF_STATE 2
  104. #define POWERON_STATE 3
  105. #define POWEROFF_STATE 4
  106. #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
  107. /* Error messages */
  108. #define INTERLOCK_OPEN 0x00000002
  109. #define ADD_NOT_SUPPORTED 0x00000003
  110. #define CARD_FUNCTIONING 0x00000005
  111. #define ADAPTER_NOT_SAME 0x00000006
  112. #define NO_ADAPTER_PRESENT 0x00000009
  113. #define NOT_ENOUGH_RESOURCES 0x0000000B
  114. #define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
  115. #define WRONG_BUS_FREQUENCY 0x0000000D
  116. #define POWER_FAILURE 0x0000000E
  117. #define REMOVE_NOT_SUPPORTED 0x00000003
  118. #define DISABLE_CARD 1
  119. /* Field definitions in Slot Capabilities Register */
  120. #define ATTN_BUTTN_PRSN 0x00000001
  121. #define PWR_CTRL_PRSN 0x00000002
  122. #define MRL_SENS_PRSN 0x00000004
  123. #define ATTN_LED_PRSN 0x00000008
  124. #define PWR_LED_PRSN 0x00000010
  125. #define HP_SUPR_RM_SUP 0x00000020
  126. #define ATTN_BUTTN(cap) (cap & ATTN_BUTTN_PRSN)
  127. #define POWER_CTRL(cap) (cap & PWR_CTRL_PRSN)
  128. #define MRL_SENS(cap) (cap & MRL_SENS_PRSN)
  129. #define ATTN_LED(cap) (cap & ATTN_LED_PRSN)
  130. #define PWR_LED(cap) (cap & PWR_LED_PRSN)
  131. #define HP_SUPR_RM(cap) (cap & HP_SUPR_RM_SUP)
  132. /*
  133. * error Messages
  134. */
  135. #define msg_initialization_err "Initialization failure, error=%d\n"
  136. #define msg_button_on "PCI slot #%s - powering on due to button press.\n"
  137. #define msg_button_off "PCI slot #%s - powering off due to button press.\n"
  138. #define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
  139. #define msg_button_ignore "PCI slot #%s - button press ignored. (action in progress...)\n"
  140. /* controller functions */
  141. extern int pciehp_event_start_thread (void);
  142. extern void pciehp_event_stop_thread (void);
  143. extern int pciehp_enable_slot (struct slot *slot);
  144. extern int pciehp_disable_slot (struct slot *slot);
  145. extern u8 pciehp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
  146. extern u8 pciehp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
  147. extern u8 pciehp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
  148. extern u8 pciehp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
  149. /* extern void long_delay (int delay); */
  150. /* pci functions */
  151. extern int pciehp_configure_device (struct slot *p_slot);
  152. extern int pciehp_unconfigure_device (struct slot *p_slot);
  153. /* Global variables */
  154. extern struct controller *pciehp_ctrl_list;
  155. /* Inline functions */
  156. static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
  157. {
  158. struct slot *slot;
  159. list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
  160. if (slot->device == device)
  161. return slot;
  162. }
  163. err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device);
  164. return NULL;
  165. }
  166. static inline int wait_for_ctrl_irq(struct controller *ctrl)
  167. {
  168. int retval = 0;
  169. DECLARE_WAITQUEUE(wait, current);
  170. add_wait_queue(&ctrl->queue, &wait);
  171. if (!pciehp_poll_mode)
  172. /* Sleep for up to 1 second */
  173. msleep_interruptible(1000);
  174. else
  175. msleep_interruptible(2500);
  176. remove_wait_queue(&ctrl->queue, &wait);
  177. if (signal_pending(current))
  178. retval = -EINTR;
  179. return retval;
  180. }
  181. int pcie_init(struct controller *ctrl, struct pcie_device *dev);
  182. struct hpc_ops {
  183. int (*power_on_slot) (struct slot *slot);
  184. int (*power_off_slot) (struct slot *slot);
  185. int (*get_power_status) (struct slot *slot, u8 *status);
  186. int (*get_attention_status) (struct slot *slot, u8 *status);
  187. int (*set_attention_status) (struct slot *slot, u8 status);
  188. int (*get_latch_status) (struct slot *slot, u8 *status);
  189. int (*get_adapter_status) (struct slot *slot, u8 *status);
  190. int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
  191. int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
  192. int (*get_max_lnk_width) (struct slot *slot, enum pcie_link_width *value);
  193. int (*get_cur_lnk_width) (struct slot *slot, enum pcie_link_width *value);
  194. int (*query_power_fault) (struct slot *slot);
  195. void (*green_led_on) (struct slot *slot);
  196. void (*green_led_off) (struct slot *slot);
  197. void (*green_led_blink) (struct slot *slot);
  198. void (*release_ctlr) (struct controller *ctrl);
  199. int (*check_lnk_status) (struct controller *ctrl);
  200. };
  201. #ifdef CONFIG_ACPI
  202. #include <acpi/acpi.h>
  203. #include <acpi/acpi_bus.h>
  204. #include <acpi/actypes.h>
  205. #include <linux/pci-acpi.h>
  206. #define pciehp_get_hp_hw_control_from_firmware(dev) \
  207. pciehp_acpi_get_hp_hw_control_from_firmware(dev)
  208. static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev,
  209. struct hotplug_params *hpp)
  210. {
  211. if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp)))
  212. return -ENODEV;
  213. return 0;
  214. }
  215. #else
  216. #define pciehp_get_hp_hw_control_from_firmware(dev) 0
  217. #define pciehp_get_hp_params_from_firmware(dev, hpp) (-ENODEV)
  218. #endif /* CONFIG_ACPI */
  219. #endif /* _PCIEHP_H */