shpchp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * Standard 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
  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 _SHPCHP_H
  30. #define _SHPCHP_H
  31. #include <linux/types.h>
  32. #include <linux/pci.h>
  33. #include <linux/delay.h>
  34. #include <asm/semaphore.h>
  35. #include <asm/io.h>
  36. #include "pci_hotplug.h"
  37. #if !defined(MODULE)
  38. #define MY_NAME "shpchp"
  39. #else
  40. #define MY_NAME THIS_MODULE->name
  41. #endif
  42. extern int shpchp_poll_mode;
  43. extern int shpchp_poll_time;
  44. extern int shpchp_debug;
  45. /*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/
  46. #define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0)
  47. #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
  48. #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
  49. #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
  50. struct pci_func {
  51. struct pci_func *next;
  52. u8 bus;
  53. u8 device;
  54. u8 function;
  55. u8 is_a_board;
  56. u16 status;
  57. u8 configured;
  58. u8 switch_save;
  59. u8 presence_save;
  60. u8 pwr_save;
  61. u32 config_space[0x20];
  62. struct pci_dev* pci_dev;
  63. };
  64. #define SLOT_MAGIC 0x67267321
  65. struct slot {
  66. u32 magic;
  67. struct slot *next;
  68. u8 bus;
  69. u8 device;
  70. u32 number;
  71. u8 is_a_board;
  72. u8 configured;
  73. u8 state;
  74. u8 switch_save;
  75. u8 presence_save;
  76. u32 capabilities;
  77. u16 reserved2;
  78. struct timer_list task_event;
  79. u8 hp_slot;
  80. struct controller *ctrl;
  81. struct hpc_ops *hpc_ops;
  82. struct hotplug_slot *hotplug_slot;
  83. struct list_head slot_list;
  84. };
  85. struct event_info {
  86. u32 event_type;
  87. u8 hp_slot;
  88. };
  89. struct controller {
  90. struct controller *next;
  91. struct semaphore crit_sect; /* critical section semaphore */
  92. void * hpc_ctlr_handle; /* HPC controller handle */
  93. int num_slots; /* Number of slots on ctlr */
  94. int slot_num_inc; /* 1 or -1 */
  95. struct pci_dev *pci_dev;
  96. struct pci_bus *pci_bus;
  97. struct event_info event_queue[10];
  98. struct slot *slot;
  99. struct hpc_ops *hpc_ops;
  100. wait_queue_head_t queue; /* sleep & wake process */
  101. u8 next_event;
  102. u8 seg;
  103. u8 bus;
  104. u8 device;
  105. u8 function;
  106. u8 rev;
  107. u8 slot_device_offset;
  108. u8 add_support;
  109. enum pci_bus_speed speed;
  110. u32 first_slot; /* First physical slot number */
  111. u8 slot_bus; /* Bus where the slots handled by this controller sit */
  112. u8 push_flag;
  113. u16 ctlrcap;
  114. u16 vendor_id;
  115. };
  116. struct hotplug_params {
  117. u8 cache_line_size;
  118. u8 latency_timer;
  119. u8 enable_serr;
  120. u8 enable_perr;
  121. };
  122. /* Define AMD SHPC ID */
  123. #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
  124. #define INT_BUTTON_IGNORE 0
  125. #define INT_PRESENCE_ON 1
  126. #define INT_PRESENCE_OFF 2
  127. #define INT_SWITCH_CLOSE 3
  128. #define INT_SWITCH_OPEN 4
  129. #define INT_POWER_FAULT 5
  130. #define INT_POWER_FAULT_CLEAR 6
  131. #define INT_BUTTON_PRESS 7
  132. #define INT_BUTTON_RELEASE 8
  133. #define INT_BUTTON_CANCEL 9
  134. #define STATIC_STATE 0
  135. #define BLINKINGON_STATE 1
  136. #define BLINKINGOFF_STATE 2
  137. #define POWERON_STATE 3
  138. #define POWEROFF_STATE 4
  139. #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
  140. /* Error messages */
  141. #define INTERLOCK_OPEN 0x00000002
  142. #define ADD_NOT_SUPPORTED 0x00000003
  143. #define CARD_FUNCTIONING 0x00000005
  144. #define ADAPTER_NOT_SAME 0x00000006
  145. #define NO_ADAPTER_PRESENT 0x00000009
  146. #define NOT_ENOUGH_RESOURCES 0x0000000B
  147. #define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
  148. #define WRONG_BUS_FREQUENCY 0x0000000D
  149. #define POWER_FAILURE 0x0000000E
  150. #define REMOVE_NOT_SUPPORTED 0x00000003
  151. #define DISABLE_CARD 1
  152. /*
  153. * error Messages
  154. */
  155. #define msg_initialization_err "Initialization failure, error=%d\n"
  156. #define msg_HPC_rev_error "Unsupported revision of the PCI hot plug controller found.\n"
  157. #define msg_HPC_non_shpc "The PCI hot plug controller is not supported by this driver.\n"
  158. #define msg_HPC_not_supported "This system is not supported by this version of shpcphd mdoule. Upgrade to a newer version of shpchpd\n"
  159. #define msg_button_on "PCI slot #%d - powering on due to button press.\n"
  160. #define msg_button_off "PCI slot #%d - powering off due to button press.\n"
  161. #define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n"
  162. #define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n"
  163. /* sysfs functions for the hotplug controller info */
  164. extern void shpchp_create_ctrl_files (struct controller *ctrl);
  165. /* controller functions */
  166. extern int shpchp_event_start_thread(void);
  167. extern void shpchp_event_stop_thread(void);
  168. extern struct pci_func *shpchp_slot_create(unsigned char busnumber);
  169. extern struct pci_func *shpchp_slot_find(unsigned char bus, unsigned char device, unsigned char index);
  170. extern int shpchp_enable_slot(struct slot *slot);
  171. extern int shpchp_disable_slot(struct slot *slot);
  172. extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id);
  173. extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id);
  174. extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id);
  175. extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id);
  176. /* pci functions */
  177. extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
  178. extern int shpchp_save_slot_config(struct controller *ctrl, struct pci_func * new_slot);
  179. extern int shpchp_configure_device(struct slot *p_slot);
  180. extern int shpchp_unconfigure_device(struct pci_func* func);
  181. extern void get_hp_hw_control_from_firmware(struct pci_dev *dev);
  182. extern void get_hp_params_from_firmware(struct pci_dev *dev,
  183. struct hotplug_params *hpp);
  184. extern int shpchprm_get_physical_slot_number(struct controller *ctrl,
  185. u32 *sun, u8 busnum, u8 devnum);
  186. /* Global variables */
  187. extern struct controller *shpchp_ctrl_list;
  188. extern struct pci_func *shpchp_slot_list[256];
  189. struct ctrl_reg {
  190. volatile u32 base_offset;
  191. volatile u32 slot_avail1;
  192. volatile u32 slot_avail2;
  193. volatile u32 slot_config;
  194. volatile u16 sec_bus_config;
  195. volatile u8 msi_ctrl;
  196. volatile u8 prog_interface;
  197. volatile u16 cmd;
  198. volatile u16 cmd_status;
  199. volatile u32 intr_loc;
  200. volatile u32 serr_loc;
  201. volatile u32 serr_intr_enable;
  202. volatile u32 slot1;
  203. volatile u32 slot2;
  204. volatile u32 slot3;
  205. volatile u32 slot4;
  206. volatile u32 slot5;
  207. volatile u32 slot6;
  208. volatile u32 slot7;
  209. volatile u32 slot8;
  210. volatile u32 slot9;
  211. volatile u32 slot10;
  212. volatile u32 slot11;
  213. volatile u32 slot12;
  214. } __attribute__ ((packed));
  215. /* offsets to the controller registers based on the above structure layout */
  216. enum ctrl_offsets {
  217. BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
  218. SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
  219. SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
  220. SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
  221. SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
  222. MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
  223. PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
  224. CMD = offsetof(struct ctrl_reg, cmd),
  225. CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
  226. INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
  227. SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
  228. SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
  229. SLOT1 = offsetof(struct ctrl_reg, slot1),
  230. SLOT2 = offsetof(struct ctrl_reg, slot2),
  231. SLOT3 = offsetof(struct ctrl_reg, slot3),
  232. SLOT4 = offsetof(struct ctrl_reg, slot4),
  233. SLOT5 = offsetof(struct ctrl_reg, slot5),
  234. SLOT6 = offsetof(struct ctrl_reg, slot6),
  235. SLOT7 = offsetof(struct ctrl_reg, slot7),
  236. SLOT8 = offsetof(struct ctrl_reg, slot8),
  237. SLOT9 = offsetof(struct ctrl_reg, slot9),
  238. SLOT10 = offsetof(struct ctrl_reg, slot10),
  239. SLOT11 = offsetof(struct ctrl_reg, slot11),
  240. SLOT12 = offsetof(struct ctrl_reg, slot12),
  241. };
  242. typedef u8(*php_intr_callback_t) (unsigned int change_id, void *instance_id);
  243. struct php_ctlr_state_s {
  244. struct php_ctlr_state_s *pnext;
  245. struct pci_dev *pci_dev;
  246. unsigned int irq;
  247. unsigned long flags; /* spinlock's */
  248. u32 slot_device_offset;
  249. u32 num_slots;
  250. struct timer_list int_poll_timer; /* Added for poll event */
  251. php_intr_callback_t attention_button_callback;
  252. php_intr_callback_t switch_change_callback;
  253. php_intr_callback_t presence_change_callback;
  254. php_intr_callback_t power_fault_callback;
  255. void *callback_instance_id;
  256. void __iomem *creg; /* Ptr to controller register space */
  257. };
  258. /* Inline functions */
  259. /* Inline functions to check the sanity of a pointer that is passed to us */
  260. static inline int slot_paranoia_check (struct slot *slot, const char *function)
  261. {
  262. if (!slot) {
  263. dbg("%s - slot == NULL", function);
  264. return -1;
  265. }
  266. if (slot->magic != SLOT_MAGIC) {
  267. dbg("%s - bad magic number for slot", function);
  268. return -1;
  269. }
  270. if (!slot->hotplug_slot) {
  271. dbg("%s - slot->hotplug_slot == NULL!", function);
  272. return -1;
  273. }
  274. return 0;
  275. }
  276. static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
  277. {
  278. struct slot *slot;
  279. if (!hotplug_slot) {
  280. dbg("%s - hotplug_slot == NULL\n", function);
  281. return NULL;
  282. }
  283. slot = (struct slot *)hotplug_slot->private;
  284. if (slot_paranoia_check (slot, function))
  285. return NULL;
  286. return slot;
  287. }
  288. static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
  289. {
  290. struct slot *p_slot, *tmp_slot = NULL;
  291. if (!ctrl)
  292. return NULL;
  293. p_slot = ctrl->slot;
  294. dbg("p_slot = %p\n", p_slot);
  295. while (p_slot && (p_slot->device != device)) {
  296. tmp_slot = p_slot;
  297. p_slot = p_slot->next;
  298. dbg("In while loop, p_slot = %p\n", p_slot);
  299. }
  300. if (p_slot == NULL) {
  301. err("ERROR: shpchp_find_slot device=0x%x\n", device);
  302. p_slot = tmp_slot;
  303. }
  304. return (p_slot);
  305. }
  306. static inline int wait_for_ctrl_irq (struct controller *ctrl)
  307. {
  308. DECLARE_WAITQUEUE(wait, current);
  309. int retval = 0;
  310. dbg("%s : start\n",__FUNCTION__);
  311. add_wait_queue(&ctrl->queue, &wait);
  312. if (!shpchp_poll_mode) {
  313. /* Sleep for up to 1 second */
  314. msleep_interruptible(1000);
  315. } else {
  316. /* Sleep for up to 2 seconds */
  317. msleep_interruptible(2000);
  318. }
  319. remove_wait_queue(&ctrl->queue, &wait);
  320. if (signal_pending(current))
  321. retval = -EINTR;
  322. dbg("%s : end\n", __FUNCTION__);
  323. return retval;
  324. }
  325. #define SLOT_NAME_SIZE 10
  326. static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
  327. {
  328. snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
  329. }
  330. enum php_ctlr_type {
  331. PCI,
  332. ISA,
  333. ACPI
  334. };
  335. int shpc_init( struct controller *ctrl, struct pci_dev *pdev,
  336. php_intr_callback_t attention_button_callback,
  337. php_intr_callback_t switch_change_callback,
  338. php_intr_callback_t presence_change_callback,
  339. php_intr_callback_t power_fault_callback);
  340. int shpc_get_ctlr_slot_config( struct controller *ctrl,
  341. int *num_ctlr_slots,
  342. int *first_device_num,
  343. int *physical_slot_num,
  344. int *updown,
  345. int *flags);
  346. struct hpc_ops {
  347. int (*power_on_slot ) (struct slot *slot);
  348. int (*slot_enable ) (struct slot *slot);
  349. int (*slot_disable ) (struct slot *slot);
  350. int (*enable_all_slots) (struct slot *slot);
  351. int (*pwr_on_all_slots) (struct slot *slot);
  352. int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed);
  353. int (*get_power_status) (struct slot *slot, u8 *status);
  354. int (*get_attention_status) (struct slot *slot, u8 *status);
  355. int (*set_attention_status) (struct slot *slot, u8 status);
  356. int (*get_latch_status) (struct slot *slot, u8 *status);
  357. int (*get_adapter_status) (struct slot *slot, u8 *status);
  358. int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
  359. int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
  360. int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed);
  361. int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode);
  362. int (*get_prog_int) (struct slot *slot, u8 *prog_int);
  363. int (*query_power_fault) (struct slot *slot);
  364. void (*green_led_on) (struct slot *slot);
  365. void (*green_led_off) (struct slot *slot);
  366. void (*green_led_blink) (struct slot *slot);
  367. void (*release_ctlr) (struct controller *ctrl);
  368. int (*check_cmd_status) (struct controller *ctrl);
  369. };
  370. #endif /* _SHPCHP_H */