cpqphp_core.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. /*
  2. * Compaq 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. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or (at
  13. * your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  18. * NON INFRINGEMENT. See the GNU General Public License for more
  19. * details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. *
  25. * Send feedback to <greg@kroah.com>
  26. *
  27. * Jan 12, 2003 - Added 66/100/133MHz PCI-X support,
  28. * Torben Mathiasen <torben.mathiasen@hp.com>
  29. *
  30. */
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/kernel.h>
  34. #include <linux/types.h>
  35. #include <linux/proc_fs.h>
  36. #include <linux/slab.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/pci.h>
  39. #include <linux/pci_hotplug.h>
  40. #include <linux/init.h>
  41. #include <linux/interrupt.h>
  42. #include <asm/uaccess.h>
  43. #include "cpqphp.h"
  44. #include "cpqphp_nvram.h"
  45. #include "../../../arch/x86/pci/pci.h" /* horrible hack showing how processor dependent we are... */
  46. /* Global variables */
  47. int cpqhp_debug;
  48. int cpqhp_legacy_mode;
  49. struct controller *cpqhp_ctrl_list; /* = NULL */
  50. struct pci_func *cpqhp_slot_list[256];
  51. /* local variables */
  52. static void __iomem *smbios_table;
  53. static void __iomem *smbios_start;
  54. static void __iomem *cpqhp_rom_start;
  55. static int power_mode;
  56. static int debug;
  57. static int initialized;
  58. #define DRIVER_VERSION "0.9.8"
  59. #define DRIVER_AUTHOR "Dan Zink <dan.zink@compaq.com>, Greg Kroah-Hartman <greg@kroah.com>"
  60. #define DRIVER_DESC "Compaq Hot Plug PCI Controller Driver"
  61. MODULE_AUTHOR(DRIVER_AUTHOR);
  62. MODULE_DESCRIPTION(DRIVER_DESC);
  63. MODULE_LICENSE("GPL");
  64. module_param(power_mode, bool, 0644);
  65. MODULE_PARM_DESC(power_mode, "Power mode enabled or not");
  66. module_param(debug, bool, 0644);
  67. MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
  68. #define CPQHPC_MODULE_MINOR 208
  69. static int one_time_init (void);
  70. static int set_attention_status (struct hotplug_slot *slot, u8 value);
  71. static int process_SI (struct hotplug_slot *slot);
  72. static int process_SS (struct hotplug_slot *slot);
  73. static int hardware_test (struct hotplug_slot *slot, u32 value);
  74. static int get_power_status (struct hotplug_slot *slot, u8 *value);
  75. static int get_attention_status (struct hotplug_slot *slot, u8 *value);
  76. static int get_latch_status (struct hotplug_slot *slot, u8 *value);
  77. static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
  78. static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  79. static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
  80. static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
  81. .owner = THIS_MODULE,
  82. .set_attention_status = set_attention_status,
  83. .enable_slot = process_SI,
  84. .disable_slot = process_SS,
  85. .hardware_test = hardware_test,
  86. .get_power_status = get_power_status,
  87. .get_attention_status = get_attention_status,
  88. .get_latch_status = get_latch_status,
  89. .get_adapter_status = get_adapter_status,
  90. .get_max_bus_speed = get_max_bus_speed,
  91. .get_cur_bus_speed = get_cur_bus_speed,
  92. };
  93. static inline int is_slot64bit(struct slot *slot)
  94. {
  95. return (readb(slot->p_sm_slot + SMBIOS_SLOT_WIDTH) == 0x06) ? 1 : 0;
  96. }
  97. static inline int is_slot66mhz(struct slot *slot)
  98. {
  99. return (readb(slot->p_sm_slot + SMBIOS_SLOT_TYPE) == 0x0E) ? 1 : 0;
  100. }
  101. /**
  102. * detect_SMBIOS_pointer - find the System Management BIOS Table in mem region.
  103. *
  104. * @begin: begin pointer for region to be scanned.
  105. * @end: end pointer for region to be scanned.
  106. *
  107. * Returns pointer to the head of the SMBIOS tables (or NULL)
  108. *
  109. */
  110. static void __iomem * detect_SMBIOS_pointer(void __iomem *begin, void __iomem *end)
  111. {
  112. void __iomem *fp;
  113. void __iomem *endp;
  114. u8 temp1, temp2, temp3, temp4;
  115. int status = 0;
  116. endp = (end - sizeof(u32) + 1);
  117. for (fp = begin; fp <= endp; fp += 16) {
  118. temp1 = readb(fp);
  119. temp2 = readb(fp+1);
  120. temp3 = readb(fp+2);
  121. temp4 = readb(fp+3);
  122. if (temp1 == '_' &&
  123. temp2 == 'S' &&
  124. temp3 == 'M' &&
  125. temp4 == '_') {
  126. status = 1;
  127. break;
  128. }
  129. }
  130. if (!status)
  131. fp = NULL;
  132. dbg("Discovered SMBIOS Entry point at %p\n", fp);
  133. return fp;
  134. }
  135. /**
  136. * init_SERR - Initializes the per slot SERR generation.
  137. *
  138. * For unexpected switch opens
  139. *
  140. */
  141. static int init_SERR(struct controller * ctrl)
  142. {
  143. u32 tempdword;
  144. u32 number_of_slots;
  145. u8 physical_slot;
  146. if (!ctrl)
  147. return 1;
  148. tempdword = ctrl->first_slot;
  149. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  150. // Loop through slots
  151. while (number_of_slots) {
  152. physical_slot = tempdword;
  153. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  154. tempdword++;
  155. number_of_slots--;
  156. }
  157. return 0;
  158. }
  159. /* nice debugging output */
  160. static int pci_print_IRQ_route (void)
  161. {
  162. struct irq_routing_table *routing_table;
  163. int len;
  164. int loop;
  165. u8 tbus, tdevice, tslot;
  166. routing_table = pcibios_get_irq_routing_table();
  167. if (routing_table == NULL) {
  168. err("No BIOS Routing Table??? Not good\n");
  169. return -ENOMEM;
  170. }
  171. len = (routing_table->size - sizeof(struct irq_routing_table)) /
  172. sizeof(struct irq_info);
  173. // Make sure I got at least one entry
  174. if (len == 0) {
  175. kfree(routing_table);
  176. return -1;
  177. }
  178. dbg("bus dev func slot\n");
  179. for (loop = 0; loop < len; ++loop) {
  180. tbus = routing_table->slots[loop].bus;
  181. tdevice = routing_table->slots[loop].devfn;
  182. tslot = routing_table->slots[loop].slot;
  183. dbg("%d %d %d %d\n", tbus, tdevice >> 3, tdevice & 0x7, tslot);
  184. }
  185. kfree(routing_table);
  186. return 0;
  187. }
  188. /**
  189. * get_subsequent_smbios_entry: get the next entry from bios table.
  190. *
  191. * Gets the first entry if previous == NULL
  192. * Otherwise, returns the next entry
  193. * Uses global SMBIOS Table pointer
  194. *
  195. * @curr: %NULL or pointer to previously returned structure
  196. *
  197. * returns a pointer to an SMBIOS structure or NULL if none found
  198. */
  199. static void __iomem *get_subsequent_smbios_entry(void __iomem *smbios_start,
  200. void __iomem *smbios_table,
  201. void __iomem *curr)
  202. {
  203. u8 bail = 0;
  204. u8 previous_byte = 1;
  205. void __iomem *p_temp;
  206. void __iomem *p_max;
  207. if (!smbios_table || !curr)
  208. return(NULL);
  209. // set p_max to the end of the table
  210. p_max = smbios_start + readw(smbios_table + ST_LENGTH);
  211. p_temp = curr;
  212. p_temp += readb(curr + SMBIOS_GENERIC_LENGTH);
  213. while ((p_temp < p_max) && !bail) {
  214. /* Look for the double NULL terminator
  215. * The first condition is the previous byte
  216. * and the second is the curr */
  217. if (!previous_byte && !(readb(p_temp))) {
  218. bail = 1;
  219. }
  220. previous_byte = readb(p_temp);
  221. p_temp++;
  222. }
  223. if (p_temp < p_max) {
  224. return p_temp;
  225. } else {
  226. return NULL;
  227. }
  228. }
  229. /**
  230. * get_SMBIOS_entry
  231. *
  232. * @type:SMBIOS structure type to be returned
  233. * @previous: %NULL or pointer to previously returned structure
  234. *
  235. * Gets the first entry of the specified type if previous == NULL
  236. * Otherwise, returns the next entry of the given type.
  237. * Uses global SMBIOS Table pointer
  238. * Uses get_subsequent_smbios_entry
  239. *
  240. * returns a pointer to an SMBIOS structure or %NULL if none found
  241. */
  242. static void __iomem *get_SMBIOS_entry(void __iomem *smbios_start,
  243. void __iomem *smbios_table,
  244. u8 type,
  245. void __iomem *previous)
  246. {
  247. if (!smbios_table)
  248. return NULL;
  249. if (!previous) {
  250. previous = smbios_start;
  251. } else {
  252. previous = get_subsequent_smbios_entry(smbios_start,
  253. smbios_table, previous);
  254. }
  255. while (previous) {
  256. if (readb(previous + SMBIOS_GENERIC_TYPE) != type) {
  257. previous = get_subsequent_smbios_entry(smbios_start,
  258. smbios_table, previous);
  259. } else {
  260. break;
  261. }
  262. }
  263. return previous;
  264. }
  265. static void release_slot(struct hotplug_slot *hotplug_slot)
  266. {
  267. struct slot *slot = hotplug_slot->private;
  268. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  269. kfree(slot->hotplug_slot->info);
  270. kfree(slot->hotplug_slot->name);
  271. kfree(slot->hotplug_slot);
  272. kfree(slot);
  273. }
  274. static int ctrl_slot_setup(struct controller *ctrl,
  275. void __iomem *smbios_start,
  276. void __iomem *smbios_table)
  277. {
  278. struct slot *slot;
  279. struct hotplug_slot *hotplug_slot;
  280. struct hotplug_slot_info *hotplug_slot_info;
  281. u8 number_of_slots;
  282. u8 slot_device;
  283. u8 slot_number;
  284. u8 ctrl_slot;
  285. u32 tempdword;
  286. void __iomem *slot_entry= NULL;
  287. int result = -ENOMEM;
  288. dbg("%s\n", __FUNCTION__);
  289. tempdword = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  290. number_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  291. slot_device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  292. slot_number = ctrl->first_slot;
  293. while (number_of_slots) {
  294. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  295. if (!slot)
  296. goto error;
  297. slot->hotplug_slot = kzalloc(sizeof(*(slot->hotplug_slot)),
  298. GFP_KERNEL);
  299. if (!slot->hotplug_slot)
  300. goto error_slot;
  301. hotplug_slot = slot->hotplug_slot;
  302. hotplug_slot->info =
  303. kzalloc(sizeof(*(hotplug_slot->info)),
  304. GFP_KERNEL);
  305. if (!hotplug_slot->info)
  306. goto error_hpslot;
  307. hotplug_slot_info = hotplug_slot->info;
  308. hotplug_slot->name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
  309. if (!hotplug_slot->name)
  310. goto error_info;
  311. slot->ctrl = ctrl;
  312. slot->bus = ctrl->bus;
  313. slot->device = slot_device;
  314. slot->number = slot_number;
  315. dbg("slot->number = %d\n", slot->number);
  316. slot_entry = get_SMBIOS_entry(smbios_start, smbios_table, 9,
  317. slot_entry);
  318. while (slot_entry && (readw(slot_entry + SMBIOS_SLOT_NUMBER) !=
  319. slot->number)) {
  320. slot_entry = get_SMBIOS_entry(smbios_start,
  321. smbios_table, 9, slot_entry);
  322. }
  323. slot->p_sm_slot = slot_entry;
  324. init_timer(&slot->task_event);
  325. slot->task_event.expires = jiffies + 5 * HZ;
  326. slot->task_event.function = cpqhp_pushbutton_thread;
  327. //FIXME: these capabilities aren't used but if they are
  328. // they need to be correctly implemented
  329. slot->capabilities |= PCISLOT_REPLACE_SUPPORTED;
  330. slot->capabilities |= PCISLOT_INTERLOCK_SUPPORTED;
  331. if (is_slot64bit(slot))
  332. slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
  333. if (is_slot66mhz(slot))
  334. slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
  335. if (ctrl->speed == PCI_SPEED_66MHz)
  336. slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
  337. ctrl_slot =
  338. slot_device - (readb(ctrl->hpc_reg + SLOT_MASK) >> 4);
  339. // Check presence
  340. slot->capabilities |=
  341. ((((~tempdword) >> 23) |
  342. ((~tempdword) >> 15)) >> ctrl_slot) & 0x02;
  343. // Check the switch state
  344. slot->capabilities |=
  345. ((~tempdword & 0xFF) >> ctrl_slot) & 0x01;
  346. // Check the slot enable
  347. slot->capabilities |=
  348. ((read_slot_enable(ctrl) << 2) >> ctrl_slot) & 0x04;
  349. /* register this slot with the hotplug pci core */
  350. hotplug_slot->release = &release_slot;
  351. hotplug_slot->private = slot;
  352. make_slot_name(hotplug_slot->name, SLOT_NAME_SIZE, slot);
  353. hotplug_slot->ops = &cpqphp_hotplug_slot_ops;
  354. hotplug_slot_info->power_status = get_slot_enabled(ctrl, slot);
  355. hotplug_slot_info->attention_status =
  356. cpq_get_attention_status(ctrl, slot);
  357. hotplug_slot_info->latch_status =
  358. cpq_get_latch_status(ctrl, slot);
  359. hotplug_slot_info->adapter_status =
  360. get_presence_status(ctrl, slot);
  361. dbg("registering bus %d, dev %d, number %d, "
  362. "ctrl->slot_device_offset %d, slot %d\n",
  363. slot->bus, slot->device,
  364. slot->number, ctrl->slot_device_offset,
  365. slot_number);
  366. result = pci_hp_register(hotplug_slot);
  367. if (result) {
  368. err("pci_hp_register failed with error %d\n", result);
  369. goto error_name;
  370. }
  371. slot->next = ctrl->slot;
  372. ctrl->slot = slot;
  373. number_of_slots--;
  374. slot_device++;
  375. slot_number++;
  376. }
  377. return 0;
  378. error_name:
  379. kfree(hotplug_slot->name);
  380. error_info:
  381. kfree(hotplug_slot_info);
  382. error_hpslot:
  383. kfree(hotplug_slot);
  384. error_slot:
  385. kfree(slot);
  386. error:
  387. return result;
  388. }
  389. static int ctrl_slot_cleanup (struct controller * ctrl)
  390. {
  391. struct slot *old_slot, *next_slot;
  392. old_slot = ctrl->slot;
  393. ctrl->slot = NULL;
  394. while (old_slot) {
  395. /* memory will be freed by the release_slot callback */
  396. next_slot = old_slot->next;
  397. pci_hp_deregister (old_slot->hotplug_slot);
  398. old_slot = next_slot;
  399. }
  400. cpqhp_remove_debugfs_files(ctrl);
  401. //Free IRQ associated with hot plug device
  402. free_irq(ctrl->interrupt, ctrl);
  403. //Unmap the memory
  404. iounmap(ctrl->hpc_reg);
  405. //Finally reclaim PCI mem
  406. release_mem_region(pci_resource_start(ctrl->pci_dev, 0),
  407. pci_resource_len(ctrl->pci_dev, 0));
  408. return(0);
  409. }
  410. //============================================================================
  411. // function: get_slot_mapping
  412. //
  413. // Description: Attempts to determine a logical slot mapping for a PCI
  414. // device. Won't work for more than one PCI-PCI bridge
  415. // in a slot.
  416. //
  417. // Input: u8 bus_num - bus number of PCI device
  418. // u8 dev_num - device number of PCI device
  419. // u8 *slot - Pointer to u8 where slot number will
  420. // be returned
  421. //
  422. // Output: SUCCESS or FAILURE
  423. //=============================================================================
  424. static int
  425. get_slot_mapping(struct pci_bus *bus, u8 bus_num, u8 dev_num, u8 *slot)
  426. {
  427. struct irq_routing_table *PCIIRQRoutingInfoLength;
  428. u32 work;
  429. long len;
  430. long loop;
  431. u8 tbus, tdevice, tslot, bridgeSlot;
  432. dbg("%s: %p, %d, %d, %p\n", __FUNCTION__, bus, bus_num, dev_num, slot);
  433. bridgeSlot = 0xFF;
  434. PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
  435. if (!PCIIRQRoutingInfoLength)
  436. return -1;
  437. len = (PCIIRQRoutingInfoLength->size -
  438. sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
  439. // Make sure I got at least one entry
  440. if (len == 0) {
  441. kfree(PCIIRQRoutingInfoLength);
  442. return -1;
  443. }
  444. for (loop = 0; loop < len; ++loop) {
  445. tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
  446. tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn >> 3;
  447. tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
  448. if ((tbus == bus_num) && (tdevice == dev_num)) {
  449. *slot = tslot;
  450. kfree(PCIIRQRoutingInfoLength);
  451. return 0;
  452. } else {
  453. /* Did not get a match on the target PCI device. Check
  454. * if the current IRQ table entry is a PCI-to-PCI bridge
  455. * device. If so, and it's secondary bus matches the
  456. * bus number for the target device, I need to save the
  457. * bridge's slot number. If I can not find an entry for
  458. * the target device, I will have to assume it's on the
  459. * other side of the bridge, and assign it the bridge's
  460. * slot. */
  461. bus->number = tbus;
  462. pci_bus_read_config_dword(bus, PCI_DEVFN(tdevice, 0),
  463. PCI_CLASS_REVISION, &work);
  464. if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
  465. pci_bus_read_config_dword(bus,
  466. PCI_DEVFN(tdevice, 0),
  467. PCI_PRIMARY_BUS, &work);
  468. // See if bridge's secondary bus matches target bus.
  469. if (((work >> 8) & 0x000000FF) == (long) bus_num) {
  470. bridgeSlot = tslot;
  471. }
  472. }
  473. }
  474. }
  475. // If we got here, we didn't find an entry in the IRQ mapping table
  476. // for the target PCI device. If we did determine that the target
  477. // device is on the other side of a PCI-to-PCI bridge, return the
  478. // slot number for the bridge.
  479. if (bridgeSlot != 0xFF) {
  480. *slot = bridgeSlot;
  481. kfree(PCIIRQRoutingInfoLength);
  482. return 0;
  483. }
  484. kfree(PCIIRQRoutingInfoLength);
  485. // Couldn't find an entry in the routing table for this PCI device
  486. return -1;
  487. }
  488. /**
  489. * cpqhp_set_attention_status - Turns the Amber LED for a slot on or off
  490. *
  491. */
  492. static int
  493. cpqhp_set_attention_status(struct controller *ctrl, struct pci_func *func,
  494. u32 status)
  495. {
  496. u8 hp_slot;
  497. if (func == NULL)
  498. return(1);
  499. hp_slot = func->device - ctrl->slot_device_offset;
  500. // Wait for exclusive access to hardware
  501. mutex_lock(&ctrl->crit_sect);
  502. if (status == 1) {
  503. amber_LED_on (ctrl, hp_slot);
  504. } else if (status == 0) {
  505. amber_LED_off (ctrl, hp_slot);
  506. } else {
  507. // Done with exclusive hardware access
  508. mutex_unlock(&ctrl->crit_sect);
  509. return(1);
  510. }
  511. set_SOGO(ctrl);
  512. // Wait for SOBS to be unset
  513. wait_for_ctrl_irq (ctrl);
  514. // Done with exclusive hardware access
  515. mutex_unlock(&ctrl->crit_sect);
  516. return(0);
  517. }
  518. /**
  519. * set_attention_status - Turns the Amber LED for a slot on or off
  520. *
  521. */
  522. static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
  523. {
  524. struct pci_func *slot_func;
  525. struct slot *slot = hotplug_slot->private;
  526. struct controller *ctrl = slot->ctrl;
  527. u8 bus;
  528. u8 devfn;
  529. u8 device;
  530. u8 function;
  531. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  532. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  533. return -ENODEV;
  534. device = devfn >> 3;
  535. function = devfn & 0x7;
  536. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  537. slot_func = cpqhp_slot_find(bus, device, function);
  538. if (!slot_func)
  539. return -ENODEV;
  540. return cpqhp_set_attention_status(ctrl, slot_func, status);
  541. }
  542. static int process_SI(struct hotplug_slot *hotplug_slot)
  543. {
  544. struct pci_func *slot_func;
  545. struct slot *slot = hotplug_slot->private;
  546. struct controller *ctrl = slot->ctrl;
  547. u8 bus;
  548. u8 devfn;
  549. u8 device;
  550. u8 function;
  551. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  552. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  553. return -ENODEV;
  554. device = devfn >> 3;
  555. function = devfn & 0x7;
  556. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  557. slot_func = cpqhp_slot_find(bus, device, function);
  558. if (!slot_func)
  559. return -ENODEV;
  560. slot_func->bus = bus;
  561. slot_func->device = device;
  562. slot_func->function = function;
  563. slot_func->configured = 0;
  564. dbg("board_added(%p, %p)\n", slot_func, ctrl);
  565. return cpqhp_process_SI(ctrl, slot_func);
  566. }
  567. static int process_SS(struct hotplug_slot *hotplug_slot)
  568. {
  569. struct pci_func *slot_func;
  570. struct slot *slot = hotplug_slot->private;
  571. struct controller *ctrl = slot->ctrl;
  572. u8 bus;
  573. u8 devfn;
  574. u8 device;
  575. u8 function;
  576. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  577. if (cpqhp_get_bus_dev(ctrl, &bus, &devfn, slot->number) == -1)
  578. return -ENODEV;
  579. device = devfn >> 3;
  580. function = devfn & 0x7;
  581. dbg("bus, dev, fn = %d, %d, %d\n", bus, device, function);
  582. slot_func = cpqhp_slot_find(bus, device, function);
  583. if (!slot_func)
  584. return -ENODEV;
  585. dbg("In %s, slot_func = %p, ctrl = %p\n", __FUNCTION__, slot_func, ctrl);
  586. return cpqhp_process_SS(ctrl, slot_func);
  587. }
  588. static int hardware_test(struct hotplug_slot *hotplug_slot, u32 value)
  589. {
  590. struct slot *slot = hotplug_slot->private;
  591. struct controller *ctrl = slot->ctrl;
  592. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  593. return cpqhp_hardware_test(ctrl, value);
  594. }
  595. static int get_power_status(struct hotplug_slot *hotplug_slot, u8 *value)
  596. {
  597. struct slot *slot = hotplug_slot->private;
  598. struct controller *ctrl = slot->ctrl;
  599. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  600. *value = get_slot_enabled(ctrl, slot);
  601. return 0;
  602. }
  603. static int get_attention_status(struct hotplug_slot *hotplug_slot, u8 *value)
  604. {
  605. struct slot *slot = hotplug_slot->private;
  606. struct controller *ctrl = slot->ctrl;
  607. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  608. *value = cpq_get_attention_status(ctrl, slot);
  609. return 0;
  610. }
  611. static int get_latch_status(struct hotplug_slot *hotplug_slot, u8 *value)
  612. {
  613. struct slot *slot = hotplug_slot->private;
  614. struct controller *ctrl = slot->ctrl;
  615. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  616. *value = cpq_get_latch_status(ctrl, slot);
  617. return 0;
  618. }
  619. static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
  620. {
  621. struct slot *slot = hotplug_slot->private;
  622. struct controller *ctrl = slot->ctrl;
  623. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  624. *value = get_presence_status(ctrl, slot);
  625. return 0;
  626. }
  627. static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  628. {
  629. struct slot *slot = hotplug_slot->private;
  630. struct controller *ctrl = slot->ctrl;
  631. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  632. *value = ctrl->speed_capability;
  633. return 0;
  634. }
  635. static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
  636. {
  637. struct slot *slot = hotplug_slot->private;
  638. struct controller *ctrl = slot->ctrl;
  639. dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
  640. *value = ctrl->speed;
  641. return 0;
  642. }
  643. static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  644. {
  645. u8 num_of_slots = 0;
  646. u8 hp_slot = 0;
  647. u8 device;
  648. u8 bus_cap;
  649. u16 temp_word;
  650. u16 vendor_id;
  651. u16 subsystem_vid;
  652. u16 subsystem_deviceid;
  653. u32 rc;
  654. struct controller *ctrl;
  655. struct pci_func *func;
  656. int err;
  657. err = pci_enable_device(pdev);
  658. if (err) {
  659. printk(KERN_ERR MY_NAME ": cannot enable PCI device %s (%d)\n",
  660. pci_name(pdev), err);
  661. return err;
  662. }
  663. // Need to read VID early b/c it's used to differentiate CPQ and INTC discovery
  664. rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);
  665. if (rc || ((vendor_id != PCI_VENDOR_ID_COMPAQ) && (vendor_id != PCI_VENDOR_ID_INTEL))) {
  666. err(msg_HPC_non_compaq_or_intel);
  667. rc = -ENODEV;
  668. goto err_disable_device;
  669. }
  670. dbg("Vendor ID: %x\n", vendor_id);
  671. dbg("revision: %d\n", pdev->revision);
  672. if ((vendor_id == PCI_VENDOR_ID_COMPAQ) && (!pdev->revision)) {
  673. err(msg_HPC_rev_error);
  674. rc = -ENODEV;
  675. goto err_disable_device;
  676. }
  677. /* Check for the proper subsytem ID's
  678. * Intel uses a different SSID programming model than Compaq.
  679. * For Intel, each SSID bit identifies a PHP capability.
  680. * Also Intel HPC's may have RID=0.
  681. */
  682. if ((pdev->revision > 2) || (vendor_id == PCI_VENDOR_ID_INTEL)) {
  683. // TODO: This code can be made to support non-Compaq or Intel subsystem IDs
  684. rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vid);
  685. if (rc) {
  686. err("%s : pci_read_config_word failed\n", __FUNCTION__);
  687. goto err_disable_device;
  688. }
  689. dbg("Subsystem Vendor ID: %x\n", subsystem_vid);
  690. if ((subsystem_vid != PCI_VENDOR_ID_COMPAQ) && (subsystem_vid != PCI_VENDOR_ID_INTEL)) {
  691. err(msg_HPC_non_compaq_or_intel);
  692. rc = -ENODEV;
  693. goto err_disable_device;
  694. }
  695. ctrl = kzalloc(sizeof(struct controller), GFP_KERNEL);
  696. if (!ctrl) {
  697. err("%s : out of memory\n", __FUNCTION__);
  698. rc = -ENOMEM;
  699. goto err_disable_device;
  700. }
  701. rc = pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subsystem_deviceid);
  702. if (rc) {
  703. err("%s : pci_read_config_word failed\n", __FUNCTION__);
  704. goto err_free_ctrl;
  705. }
  706. info("Hot Plug Subsystem Device ID: %x\n", subsystem_deviceid);
  707. /* Set Vendor ID, so it can be accessed later from other functions */
  708. ctrl->vendor_id = vendor_id;
  709. switch (subsystem_vid) {
  710. case PCI_VENDOR_ID_COMPAQ:
  711. if (pdev->revision >= 0x13) { /* CIOBX */
  712. ctrl->push_flag = 1;
  713. ctrl->slot_switch_type = 1;
  714. ctrl->push_button = 1;
  715. ctrl->pci_config_space = 1;
  716. ctrl->defeature_PHP = 1;
  717. ctrl->pcix_support = 1;
  718. ctrl->pcix_speed_capability = 1;
  719. pci_read_config_byte(pdev, 0x41, &bus_cap);
  720. if (bus_cap & 0x80) {
  721. dbg("bus max supports 133MHz PCI-X\n");
  722. ctrl->speed_capability = PCI_SPEED_133MHz_PCIX;
  723. break;
  724. }
  725. if (bus_cap & 0x40) {
  726. dbg("bus max supports 100MHz PCI-X\n");
  727. ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
  728. break;
  729. }
  730. if (bus_cap & 20) {
  731. dbg("bus max supports 66MHz PCI-X\n");
  732. ctrl->speed_capability = PCI_SPEED_66MHz_PCIX;
  733. break;
  734. }
  735. if (bus_cap & 10) {
  736. dbg("bus max supports 66MHz PCI\n");
  737. ctrl->speed_capability = PCI_SPEED_66MHz;
  738. break;
  739. }
  740. break;
  741. }
  742. switch (subsystem_deviceid) {
  743. case PCI_SUB_HPC_ID:
  744. /* Original 6500/7000 implementation */
  745. ctrl->slot_switch_type = 1;
  746. ctrl->speed_capability = PCI_SPEED_33MHz;
  747. ctrl->push_button = 0;
  748. ctrl->pci_config_space = 1;
  749. ctrl->defeature_PHP = 1;
  750. ctrl->pcix_support = 0;
  751. ctrl->pcix_speed_capability = 0;
  752. break;
  753. case PCI_SUB_HPC_ID2:
  754. /* First Pushbutton implementation */
  755. ctrl->push_flag = 1;
  756. ctrl->slot_switch_type = 1;
  757. ctrl->speed_capability = PCI_SPEED_33MHz;
  758. ctrl->push_button = 1;
  759. ctrl->pci_config_space = 1;
  760. ctrl->defeature_PHP = 1;
  761. ctrl->pcix_support = 0;
  762. ctrl->pcix_speed_capability = 0;
  763. break;
  764. case PCI_SUB_HPC_ID_INTC:
  765. /* Third party (6500/7000) */
  766. ctrl->slot_switch_type = 1;
  767. ctrl->speed_capability = PCI_SPEED_33MHz;
  768. ctrl->push_button = 0;
  769. ctrl->pci_config_space = 1;
  770. ctrl->defeature_PHP = 1;
  771. ctrl->pcix_support = 0;
  772. ctrl->pcix_speed_capability = 0;
  773. break;
  774. case PCI_SUB_HPC_ID3:
  775. /* First 66 Mhz implementation */
  776. ctrl->push_flag = 1;
  777. ctrl->slot_switch_type = 1;
  778. ctrl->speed_capability = PCI_SPEED_66MHz;
  779. ctrl->push_button = 1;
  780. ctrl->pci_config_space = 1;
  781. ctrl->defeature_PHP = 1;
  782. ctrl->pcix_support = 0;
  783. ctrl->pcix_speed_capability = 0;
  784. break;
  785. case PCI_SUB_HPC_ID4:
  786. /* First PCI-X implementation, 100MHz */
  787. ctrl->push_flag = 1;
  788. ctrl->slot_switch_type = 1;
  789. ctrl->speed_capability = PCI_SPEED_100MHz_PCIX;
  790. ctrl->push_button = 1;
  791. ctrl->pci_config_space = 1;
  792. ctrl->defeature_PHP = 1;
  793. ctrl->pcix_support = 1;
  794. ctrl->pcix_speed_capability = 0;
  795. break;
  796. default:
  797. err(msg_HPC_not_supported);
  798. rc = -ENODEV;
  799. goto err_free_ctrl;
  800. }
  801. break;
  802. case PCI_VENDOR_ID_INTEL:
  803. /* Check for speed capability (0=33, 1=66) */
  804. if (subsystem_deviceid & 0x0001) {
  805. ctrl->speed_capability = PCI_SPEED_66MHz;
  806. } else {
  807. ctrl->speed_capability = PCI_SPEED_33MHz;
  808. }
  809. /* Check for push button */
  810. if (subsystem_deviceid & 0x0002) {
  811. /* no push button */
  812. ctrl->push_button = 0;
  813. } else {
  814. /* push button supported */
  815. ctrl->push_button = 1;
  816. }
  817. /* Check for slot switch type (0=mechanical, 1=not mechanical) */
  818. if (subsystem_deviceid & 0x0004) {
  819. /* no switch */
  820. ctrl->slot_switch_type = 0;
  821. } else {
  822. /* switch */
  823. ctrl->slot_switch_type = 1;
  824. }
  825. /* PHP Status (0=De-feature PHP, 1=Normal operation) */
  826. if (subsystem_deviceid & 0x0008) {
  827. ctrl->defeature_PHP = 1; // PHP supported
  828. } else {
  829. ctrl->defeature_PHP = 0; // PHP not supported
  830. }
  831. /* Alternate Base Address Register Interface (0=not supported, 1=supported) */
  832. if (subsystem_deviceid & 0x0010) {
  833. ctrl->alternate_base_address = 1; // supported
  834. } else {
  835. ctrl->alternate_base_address = 0; // not supported
  836. }
  837. /* PCI Config Space Index (0=not supported, 1=supported) */
  838. if (subsystem_deviceid & 0x0020) {
  839. ctrl->pci_config_space = 1; // supported
  840. } else {
  841. ctrl->pci_config_space = 0; // not supported
  842. }
  843. /* PCI-X support */
  844. if (subsystem_deviceid & 0x0080) {
  845. /* PCI-X capable */
  846. ctrl->pcix_support = 1;
  847. /* Frequency of operation in PCI-X mode */
  848. if (subsystem_deviceid & 0x0040) {
  849. /* 133MHz PCI-X if bit 7 is 1 */
  850. ctrl->pcix_speed_capability = 1;
  851. } else {
  852. /* 100MHz PCI-X if bit 7 is 1 and bit 0 is 0, */
  853. /* 66MHz PCI-X if bit 7 is 1 and bit 0 is 1 */
  854. ctrl->pcix_speed_capability = 0;
  855. }
  856. } else {
  857. /* Conventional PCI */
  858. ctrl->pcix_support = 0;
  859. ctrl->pcix_speed_capability = 0;
  860. }
  861. break;
  862. default:
  863. err(msg_HPC_not_supported);
  864. rc = -ENODEV;
  865. goto err_free_ctrl;
  866. }
  867. } else {
  868. err(msg_HPC_not_supported);
  869. return -ENODEV;
  870. }
  871. // Tell the user that we found one.
  872. info("Initializing the PCI hot plug controller residing on PCI bus %d\n",
  873. pdev->bus->number);
  874. dbg("Hotplug controller capabilities:\n");
  875. dbg(" speed_capability %d\n", ctrl->speed_capability);
  876. dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ?
  877. "switch present" : "no switch");
  878. dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ?
  879. "PHP supported" : "PHP not supported");
  880. dbg(" alternate_base_address %s\n", ctrl->alternate_base_address ?
  881. "supported" : "not supported");
  882. dbg(" pci_config_space %s\n", ctrl->pci_config_space ?
  883. "supported" : "not supported");
  884. dbg(" pcix_speed_capability %s\n", ctrl->pcix_speed_capability ?
  885. "supported" : "not supported");
  886. dbg(" pcix_support %s\n", ctrl->pcix_support ?
  887. "supported" : "not supported");
  888. ctrl->pci_dev = pdev;
  889. pci_set_drvdata(pdev, ctrl);
  890. /* make our own copy of the pci bus structure,
  891. * as we like tweaking it a lot */
  892. ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL);
  893. if (!ctrl->pci_bus) {
  894. err("out of memory\n");
  895. rc = -ENOMEM;
  896. goto err_free_ctrl;
  897. }
  898. memcpy(ctrl->pci_bus, pdev->bus, sizeof(*ctrl->pci_bus));
  899. ctrl->bus = pdev->bus->number;
  900. ctrl->rev = pdev->revision;
  901. dbg("bus device function rev: %d %d %d %d\n", ctrl->bus,
  902. PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), ctrl->rev);
  903. mutex_init(&ctrl->crit_sect);
  904. init_waitqueue_head(&ctrl->queue);
  905. /* initialize our threads if they haven't already been started up */
  906. rc = one_time_init();
  907. if (rc) {
  908. goto err_free_bus;
  909. }
  910. dbg("pdev = %p\n", pdev);
  911. dbg("pci resource start %llx\n", (unsigned long long)pci_resource_start(pdev, 0));
  912. dbg("pci resource len %llx\n", (unsigned long long)pci_resource_len(pdev, 0));
  913. if (!request_mem_region(pci_resource_start(pdev, 0),
  914. pci_resource_len(pdev, 0), MY_NAME)) {
  915. err("cannot reserve MMIO region\n");
  916. rc = -ENOMEM;
  917. goto err_free_bus;
  918. }
  919. ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0),
  920. pci_resource_len(pdev, 0));
  921. if (!ctrl->hpc_reg) {
  922. err("cannot remap MMIO region %llx @ %llx\n",
  923. (unsigned long long)pci_resource_len(pdev, 0),
  924. (unsigned long long)pci_resource_start(pdev, 0));
  925. rc = -ENODEV;
  926. goto err_free_mem_region;
  927. }
  928. // Check for 66Mhz operation
  929. ctrl->speed = get_controller_speed(ctrl);
  930. /********************************************************
  931. *
  932. * Save configuration headers for this and
  933. * subordinate PCI buses
  934. *
  935. ********************************************************/
  936. // find the physical slot number of the first hot plug slot
  937. /* Get slot won't work for devices behind bridges, but
  938. * in this case it will always be called for the "base"
  939. * bus/dev/func of a slot.
  940. * CS: this is leveraging the PCIIRQ routing code from the kernel
  941. * (pci-pc.c: get_irq_routing_table) */
  942. rc = get_slot_mapping(ctrl->pci_bus, pdev->bus->number,
  943. (readb(ctrl->hpc_reg + SLOT_MASK) >> 4),
  944. &(ctrl->first_slot));
  945. dbg("get_slot_mapping: first_slot = %d, returned = %d\n",
  946. ctrl->first_slot, rc);
  947. if (rc) {
  948. err(msg_initialization_err, rc);
  949. goto err_iounmap;
  950. }
  951. // Store PCI Config Space for all devices on this bus
  952. rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK));
  953. if (rc) {
  954. err("%s: unable to save PCI configuration data, error %d\n",
  955. __FUNCTION__, rc);
  956. goto err_iounmap;
  957. }
  958. /*
  959. * Get IO, memory, and IRQ resources for new devices
  960. */
  961. // The next line is required for cpqhp_find_available_resources
  962. ctrl->interrupt = pdev->irq;
  963. if (ctrl->interrupt < 0x10) {
  964. cpqhp_legacy_mode = 1;
  965. dbg("System seems to be configured for Full Table Mapped MPS mode\n");
  966. }
  967. ctrl->cfgspc_irq = 0;
  968. pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq);
  969. rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start);
  970. ctrl->add_support = !rc;
  971. if (rc) {
  972. dbg("cpqhp_find_available_resources = 0x%x\n", rc);
  973. err("unable to locate PCI configuration resources for hot plug add.\n");
  974. goto err_iounmap;
  975. }
  976. /*
  977. * Finish setting up the hot plug ctrl device
  978. */
  979. ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  980. dbg("NumSlots %d \n", ctrl->slot_device_offset);
  981. ctrl->next_event = 0;
  982. /* Setup the slot information structures */
  983. rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table);
  984. if (rc) {
  985. err(msg_initialization_err, 6);
  986. err("%s: unable to save PCI configuration data, error %d\n",
  987. __FUNCTION__, rc);
  988. goto err_iounmap;
  989. }
  990. /* Mask all general input interrupts */
  991. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK);
  992. /* set up the interrupt */
  993. dbg("HPC interrupt = %d \n", ctrl->interrupt);
  994. if (request_irq(ctrl->interrupt, cpqhp_ctrl_intr,
  995. IRQF_SHARED, MY_NAME, ctrl)) {
  996. err("Can't get irq %d for the hotplug pci controller\n",
  997. ctrl->interrupt);
  998. rc = -ENODEV;
  999. goto err_iounmap;
  1000. }
  1001. /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */
  1002. temp_word = readw(ctrl->hpc_reg + MISC);
  1003. temp_word |= 0x4006;
  1004. writew(temp_word, ctrl->hpc_reg + MISC);
  1005. // Changed 05/05/97 to clear all interrupts at start
  1006. writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR);
  1007. ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR);
  1008. writel(0x0L, ctrl->hpc_reg + INT_MASK);
  1009. if (!cpqhp_ctrl_list) {
  1010. cpqhp_ctrl_list = ctrl;
  1011. ctrl->next = NULL;
  1012. } else {
  1013. ctrl->next = cpqhp_ctrl_list;
  1014. cpqhp_ctrl_list = ctrl;
  1015. }
  1016. // turn off empty slots here unless command line option "ON" set
  1017. // Wait for exclusive access to hardware
  1018. mutex_lock(&ctrl->crit_sect);
  1019. num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F;
  1020. // find first device number for the ctrl
  1021. device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4;
  1022. while (num_of_slots) {
  1023. dbg("num_of_slots: %d\n", num_of_slots);
  1024. func = cpqhp_slot_find(ctrl->bus, device, 0);
  1025. if (!func)
  1026. break;
  1027. hp_slot = func->device - ctrl->slot_device_offset;
  1028. dbg("hp_slot: %d\n", hp_slot);
  1029. // We have to save the presence info for these slots
  1030. temp_word = ctrl->ctrl_int_comp >> 16;
  1031. func->presence_save = (temp_word >> hp_slot) & 0x01;
  1032. func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02;
  1033. if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) {
  1034. func->switch_save = 0;
  1035. } else {
  1036. func->switch_save = 0x10;
  1037. }
  1038. if (!power_mode) {
  1039. if (!func->is_a_board) {
  1040. green_LED_off(ctrl, hp_slot);
  1041. slot_disable(ctrl, hp_slot);
  1042. }
  1043. }
  1044. device++;
  1045. num_of_slots--;
  1046. }
  1047. if (!power_mode) {
  1048. set_SOGO(ctrl);
  1049. // Wait for SOBS to be unset
  1050. wait_for_ctrl_irq(ctrl);
  1051. }
  1052. rc = init_SERR(ctrl);
  1053. if (rc) {
  1054. err("init_SERR failed\n");
  1055. mutex_unlock(&ctrl->crit_sect);
  1056. goto err_free_irq;
  1057. }
  1058. // Done with exclusive hardware access
  1059. mutex_unlock(&ctrl->crit_sect);
  1060. cpqhp_create_debugfs_files(ctrl);
  1061. return 0;
  1062. err_free_irq:
  1063. free_irq(ctrl->interrupt, ctrl);
  1064. err_iounmap:
  1065. iounmap(ctrl->hpc_reg);
  1066. err_free_mem_region:
  1067. release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
  1068. err_free_bus:
  1069. kfree(ctrl->pci_bus);
  1070. err_free_ctrl:
  1071. kfree(ctrl);
  1072. err_disable_device:
  1073. pci_disable_device(pdev);
  1074. return rc;
  1075. }
  1076. static int one_time_init(void)
  1077. {
  1078. int loop;
  1079. int retval = 0;
  1080. if (initialized)
  1081. return 0;
  1082. power_mode = 0;
  1083. retval = pci_print_IRQ_route();
  1084. if (retval)
  1085. goto error;
  1086. dbg("Initialize + Start the notification mechanism \n");
  1087. retval = cpqhp_event_start_thread();
  1088. if (retval)
  1089. goto error;
  1090. dbg("Initialize slot lists\n");
  1091. for (loop = 0; loop < 256; loop++) {
  1092. cpqhp_slot_list[loop] = NULL;
  1093. }
  1094. // FIXME: We also need to hook the NMI handler eventually.
  1095. // this also needs to be worked with Christoph
  1096. // register_NMI_handler();
  1097. // Map rom address
  1098. cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN);
  1099. if (!cpqhp_rom_start) {
  1100. err ("Could not ioremap memory region for ROM\n");
  1101. retval = -EIO;
  1102. goto error;
  1103. }
  1104. /* Now, map the int15 entry point if we are on compaq specific hardware */
  1105. compaq_nvram_init(cpqhp_rom_start);
  1106. /* Map smbios table entry point structure */
  1107. smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start,
  1108. cpqhp_rom_start + ROM_PHY_LEN);
  1109. if (!smbios_table) {
  1110. err ("Could not find the SMBIOS pointer in memory\n");
  1111. retval = -EIO;
  1112. goto error_rom_start;
  1113. }
  1114. smbios_start = ioremap(readl(smbios_table + ST_ADDRESS),
  1115. readw(smbios_table + ST_LENGTH));
  1116. if (!smbios_start) {
  1117. err ("Could not ioremap memory region taken from SMBIOS values\n");
  1118. retval = -EIO;
  1119. goto error_smbios_start;
  1120. }
  1121. initialized = 1;
  1122. return retval;
  1123. error_smbios_start:
  1124. iounmap(smbios_start);
  1125. error_rom_start:
  1126. iounmap(cpqhp_rom_start);
  1127. error:
  1128. return retval;
  1129. }
  1130. static void __exit unload_cpqphpd(void)
  1131. {
  1132. struct pci_func *next;
  1133. struct pci_func *TempSlot;
  1134. int loop;
  1135. u32 rc;
  1136. struct controller *ctrl;
  1137. struct controller *tctrl;
  1138. struct pci_resource *res;
  1139. struct pci_resource *tres;
  1140. rc = compaq_nvram_store(cpqhp_rom_start);
  1141. ctrl = cpqhp_ctrl_list;
  1142. while (ctrl) {
  1143. if (ctrl->hpc_reg) {
  1144. u16 misc;
  1145. rc = read_slot_enable (ctrl);
  1146. writeb(0, ctrl->hpc_reg + SLOT_SERR);
  1147. writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK);
  1148. misc = readw(ctrl->hpc_reg + MISC);
  1149. misc &= 0xFFFD;
  1150. writew(misc, ctrl->hpc_reg + MISC);
  1151. }
  1152. ctrl_slot_cleanup(ctrl);
  1153. res = ctrl->io_head;
  1154. while (res) {
  1155. tres = res;
  1156. res = res->next;
  1157. kfree(tres);
  1158. }
  1159. res = ctrl->mem_head;
  1160. while (res) {
  1161. tres = res;
  1162. res = res->next;
  1163. kfree(tres);
  1164. }
  1165. res = ctrl->p_mem_head;
  1166. while (res) {
  1167. tres = res;
  1168. res = res->next;
  1169. kfree(tres);
  1170. }
  1171. res = ctrl->bus_head;
  1172. while (res) {
  1173. tres = res;
  1174. res = res->next;
  1175. kfree(tres);
  1176. }
  1177. kfree (ctrl->pci_bus);
  1178. tctrl = ctrl;
  1179. ctrl = ctrl->next;
  1180. kfree(tctrl);
  1181. }
  1182. for (loop = 0; loop < 256; loop++) {
  1183. next = cpqhp_slot_list[loop];
  1184. while (next != NULL) {
  1185. res = next->io_head;
  1186. while (res) {
  1187. tres = res;
  1188. res = res->next;
  1189. kfree(tres);
  1190. }
  1191. res = next->mem_head;
  1192. while (res) {
  1193. tres = res;
  1194. res = res->next;
  1195. kfree(tres);
  1196. }
  1197. res = next->p_mem_head;
  1198. while (res) {
  1199. tres = res;
  1200. res = res->next;
  1201. kfree(tres);
  1202. }
  1203. res = next->bus_head;
  1204. while (res) {
  1205. tres = res;
  1206. res = res->next;
  1207. kfree(tres);
  1208. }
  1209. TempSlot = next;
  1210. next = next->next;
  1211. kfree(TempSlot);
  1212. }
  1213. }
  1214. // Stop the notification mechanism
  1215. if (initialized)
  1216. cpqhp_event_stop_thread();
  1217. //unmap the rom address
  1218. if (cpqhp_rom_start)
  1219. iounmap(cpqhp_rom_start);
  1220. if (smbios_start)
  1221. iounmap(smbios_start);
  1222. }
  1223. static struct pci_device_id hpcd_pci_tbl[] = {
  1224. {
  1225. /* handle any PCI Hotplug controller */
  1226. .class = ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00),
  1227. .class_mask = ~0,
  1228. /* no matter who makes it */
  1229. .vendor = PCI_ANY_ID,
  1230. .device = PCI_ANY_ID,
  1231. .subvendor = PCI_ANY_ID,
  1232. .subdevice = PCI_ANY_ID,
  1233. }, { /* end: all zeroes */ }
  1234. };
  1235. MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);
  1236. static struct pci_driver cpqhpc_driver = {
  1237. .name = "compaq_pci_hotplug",
  1238. .id_table = hpcd_pci_tbl,
  1239. .probe = cpqhpc_probe,
  1240. /* remove: cpqhpc_remove_one, */
  1241. };
  1242. static int __init cpqhpc_init(void)
  1243. {
  1244. int result;
  1245. cpqhp_debug = debug;
  1246. info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
  1247. cpqhp_initialize_debugfs();
  1248. result = pci_register_driver(&cpqhpc_driver);
  1249. dbg("pci_register_driver = %d\n", result);
  1250. return result;
  1251. }
  1252. static void __exit cpqhpc_cleanup(void)
  1253. {
  1254. dbg("unload_cpqphpd()\n");
  1255. unload_cpqphpd();
  1256. dbg("pci_unregister_driver\n");
  1257. pci_unregister_driver(&cpqhpc_driver);
  1258. cpqhp_shutdown_debugfs();
  1259. }
  1260. module_init(cpqhpc_init);
  1261. module_exit(cpqhpc_cleanup);