cpqphp_core.c 39 KB

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