cpqphp_core.c 38 KB

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