shpchp.h 14 KB

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