cpqphp_core.c 38 KB

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