cpqphp_core.c 34 KB

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