pci_link.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /*
  2. * pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $)
  3. *
  4. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  5. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  6. * Copyright (C) 2002 Dominik Brodowski <devel@brodo.de>
  7. *
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  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. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  23. *
  24. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. *
  26. * TBD:
  27. * 1. Support more than one IRQ resource entry per link device (index).
  28. * 2. Implement start/stop mechanism and use ACPI Bus Driver facilities
  29. * for IRQ management (e.g. start()->_SRS).
  30. */
  31. #include <linux/syscore_ops.h>
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <linux/init.h>
  35. #include <linux/types.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/pm.h>
  38. #include <linux/pci.h>
  39. #include <linux/mutex.h>
  40. #include <linux/slab.h>
  41. #include <acpi/acpi_bus.h>
  42. #include <acpi/acpi_drivers.h>
  43. #define PREFIX "ACPI: "
  44. #define _COMPONENT ACPI_PCI_COMPONENT
  45. ACPI_MODULE_NAME("pci_link");
  46. #define ACPI_PCI_LINK_CLASS "pci_irq_routing"
  47. #define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
  48. #define ACPI_PCI_LINK_FILE_INFO "info"
  49. #define ACPI_PCI_LINK_FILE_STATUS "state"
  50. #define ACPI_PCI_LINK_MAX_POSSIBLE 16
  51. static int acpi_pci_link_add(struct acpi_device *device);
  52. static int acpi_pci_link_remove(struct acpi_device *device, int type);
  53. static const struct acpi_device_id link_device_ids[] = {
  54. {"PNP0C0F", 0},
  55. {"", 0},
  56. };
  57. MODULE_DEVICE_TABLE(acpi, link_device_ids);
  58. static struct acpi_driver acpi_pci_link_driver = {
  59. .name = "pci_link",
  60. .class = ACPI_PCI_LINK_CLASS,
  61. .ids = link_device_ids,
  62. .ops = {
  63. .add = acpi_pci_link_add,
  64. .remove = acpi_pci_link_remove,
  65. },
  66. };
  67. /*
  68. * If a link is initialized, we never change its active and initialized
  69. * later even the link is disable. Instead, we just repick the active irq
  70. */
  71. struct acpi_pci_link_irq {
  72. u8 active; /* Current IRQ */
  73. u8 triggering; /* All IRQs */
  74. u8 polarity; /* All IRQs */
  75. u8 resource_type;
  76. u8 possible_count;
  77. u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
  78. u8 initialized:1;
  79. u8 reserved:7;
  80. };
  81. struct acpi_pci_link {
  82. struct list_head list;
  83. struct acpi_device *device;
  84. struct acpi_pci_link_irq irq;
  85. int refcnt;
  86. };
  87. static LIST_HEAD(acpi_link_list);
  88. static DEFINE_MUTEX(acpi_link_lock);
  89. /* --------------------------------------------------------------------------
  90. PCI Link Device Management
  91. -------------------------------------------------------------------------- */
  92. /*
  93. * set context (link) possible list from resource list
  94. */
  95. static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource,
  96. void *context)
  97. {
  98. struct acpi_pci_link *link = context;
  99. u32 i;
  100. switch (resource->type) {
  101. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  102. case ACPI_RESOURCE_TYPE_END_TAG:
  103. return AE_OK;
  104. case ACPI_RESOURCE_TYPE_IRQ:
  105. {
  106. struct acpi_resource_irq *p = &resource->data.irq;
  107. if (!p || !p->interrupt_count) {
  108. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  109. "Blank _PRS IRQ resource\n"));
  110. return AE_OK;
  111. }
  112. for (i = 0;
  113. (i < p->interrupt_count
  114. && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
  115. if (!p->interrupts[i]) {
  116. printk(KERN_WARNING PREFIX
  117. "Invalid _PRS IRQ %d\n",
  118. p->interrupts[i]);
  119. continue;
  120. }
  121. link->irq.possible[i] = p->interrupts[i];
  122. link->irq.possible_count++;
  123. }
  124. link->irq.triggering = p->triggering;
  125. link->irq.polarity = p->polarity;
  126. link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
  127. break;
  128. }
  129. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  130. {
  131. struct acpi_resource_extended_irq *p =
  132. &resource->data.extended_irq;
  133. if (!p || !p->interrupt_count) {
  134. printk(KERN_WARNING PREFIX
  135. "Blank _PRS EXT IRQ resource\n");
  136. return AE_OK;
  137. }
  138. for (i = 0;
  139. (i < p->interrupt_count
  140. && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
  141. if (!p->interrupts[i]) {
  142. printk(KERN_WARNING PREFIX
  143. "Invalid _PRS IRQ %d\n",
  144. p->interrupts[i]);
  145. continue;
  146. }
  147. link->irq.possible[i] = p->interrupts[i];
  148. link->irq.possible_count++;
  149. }
  150. link->irq.triggering = p->triggering;
  151. link->irq.polarity = p->polarity;
  152. link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
  153. break;
  154. }
  155. default:
  156. printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n",
  157. resource->type);
  158. return AE_OK;
  159. }
  160. return AE_CTRL_TERMINATE;
  161. }
  162. static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
  163. {
  164. acpi_status status;
  165. status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
  166. acpi_pci_link_check_possible, link);
  167. if (ACPI_FAILURE(status)) {
  168. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
  169. return -ENODEV;
  170. }
  171. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  172. "Found %d possible IRQs\n",
  173. link->irq.possible_count));
  174. return 0;
  175. }
  176. static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource,
  177. void *context)
  178. {
  179. int *irq = context;
  180. switch (resource->type) {
  181. case ACPI_RESOURCE_TYPE_START_DEPENDENT:
  182. case ACPI_RESOURCE_TYPE_END_TAG:
  183. return AE_OK;
  184. case ACPI_RESOURCE_TYPE_IRQ:
  185. {
  186. struct acpi_resource_irq *p = &resource->data.irq;
  187. if (!p || !p->interrupt_count) {
  188. /*
  189. * IRQ descriptors may have no IRQ# bits set,
  190. * particularly those those w/ _STA disabled
  191. */
  192. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  193. "Blank _CRS IRQ resource\n"));
  194. return AE_OK;
  195. }
  196. *irq = p->interrupts[0];
  197. break;
  198. }
  199. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  200. {
  201. struct acpi_resource_extended_irq *p =
  202. &resource->data.extended_irq;
  203. if (!p || !p->interrupt_count) {
  204. /*
  205. * extended IRQ descriptors must
  206. * return at least 1 IRQ
  207. */
  208. printk(KERN_WARNING PREFIX
  209. "Blank _CRS EXT IRQ resource\n");
  210. return AE_OK;
  211. }
  212. *irq = p->interrupts[0];
  213. break;
  214. }
  215. break;
  216. default:
  217. printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n",
  218. resource->type);
  219. return AE_OK;
  220. }
  221. return AE_CTRL_TERMINATE;
  222. }
  223. /*
  224. * Run _CRS and set link->irq.active
  225. *
  226. * return value:
  227. * 0 - success
  228. * !0 - failure
  229. */
  230. static int acpi_pci_link_get_current(struct acpi_pci_link *link)
  231. {
  232. int result = 0;
  233. acpi_status status;
  234. int irq = 0;
  235. link->irq.active = 0;
  236. /* in practice, status disabled is meaningless, ignore it */
  237. if (acpi_strict) {
  238. /* Query _STA, set link->device->status */
  239. result = acpi_bus_get_status(link->device);
  240. if (result) {
  241. printk(KERN_ERR PREFIX "Unable to read status\n");
  242. goto end;
  243. }
  244. if (!link->device->status.enabled) {
  245. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
  246. return 0;
  247. }
  248. }
  249. /*
  250. * Query and parse _CRS to get the current IRQ assignment.
  251. */
  252. status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
  253. acpi_pci_link_check_current, &irq);
  254. if (ACPI_FAILURE(status)) {
  255. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
  256. result = -ENODEV;
  257. goto end;
  258. }
  259. if (acpi_strict && !irq) {
  260. printk(KERN_ERR PREFIX "_CRS returned 0\n");
  261. result = -ENODEV;
  262. }
  263. link->irq.active = irq;
  264. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
  265. end:
  266. return result;
  267. }
  268. static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
  269. {
  270. int result;
  271. acpi_status status;
  272. struct {
  273. struct acpi_resource res;
  274. struct acpi_resource end;
  275. } *resource;
  276. struct acpi_buffer buffer = { 0, NULL };
  277. if (!irq)
  278. return -EINVAL;
  279. resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
  280. if (!resource)
  281. return -ENOMEM;
  282. buffer.length = sizeof(*resource) + 1;
  283. buffer.pointer = resource;
  284. switch (link->irq.resource_type) {
  285. case ACPI_RESOURCE_TYPE_IRQ:
  286. resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
  287. resource->res.length = sizeof(struct acpi_resource);
  288. resource->res.data.irq.triggering = link->irq.triggering;
  289. resource->res.data.irq.polarity =
  290. link->irq.polarity;
  291. if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
  292. resource->res.data.irq.sharable =
  293. ACPI_EXCLUSIVE;
  294. else
  295. resource->res.data.irq.sharable = ACPI_SHARED;
  296. resource->res.data.irq.interrupt_count = 1;
  297. resource->res.data.irq.interrupts[0] = irq;
  298. break;
  299. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  300. resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
  301. resource->res.length = sizeof(struct acpi_resource);
  302. resource->res.data.extended_irq.producer_consumer =
  303. ACPI_CONSUMER;
  304. resource->res.data.extended_irq.triggering =
  305. link->irq.triggering;
  306. resource->res.data.extended_irq.polarity =
  307. link->irq.polarity;
  308. if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
  309. resource->res.data.irq.sharable =
  310. ACPI_EXCLUSIVE;
  311. else
  312. resource->res.data.irq.sharable = ACPI_SHARED;
  313. resource->res.data.extended_irq.interrupt_count = 1;
  314. resource->res.data.extended_irq.interrupts[0] = irq;
  315. /* ignore resource_source, it's optional */
  316. break;
  317. default:
  318. printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
  319. result = -EINVAL;
  320. goto end;
  321. }
  322. resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
  323. /* Attempt to set the resource */
  324. status = acpi_set_current_resources(link->device->handle, &buffer);
  325. /* check for total failure */
  326. if (ACPI_FAILURE(status)) {
  327. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
  328. result = -ENODEV;
  329. goto end;
  330. }
  331. /* Query _STA, set device->status */
  332. result = acpi_bus_get_status(link->device);
  333. if (result) {
  334. printk(KERN_ERR PREFIX "Unable to read status\n");
  335. goto end;
  336. }
  337. if (!link->device->status.enabled) {
  338. printk(KERN_WARNING PREFIX
  339. "%s [%s] disabled and referenced, BIOS bug\n",
  340. acpi_device_name(link->device),
  341. acpi_device_bid(link->device));
  342. }
  343. /* Query _CRS, set link->irq.active */
  344. result = acpi_pci_link_get_current(link);
  345. if (result) {
  346. goto end;
  347. }
  348. /*
  349. * Is current setting not what we set?
  350. * set link->irq.active
  351. */
  352. if (link->irq.active != irq) {
  353. /*
  354. * policy: when _CRS doesn't return what we just _SRS
  355. * assume _SRS worked and override _CRS value.
  356. */
  357. printk(KERN_WARNING PREFIX
  358. "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
  359. acpi_device_name(link->device),
  360. acpi_device_bid(link->device), link->irq.active, irq);
  361. link->irq.active = irq;
  362. }
  363. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
  364. end:
  365. kfree(resource);
  366. return result;
  367. }
  368. /* --------------------------------------------------------------------------
  369. PCI Link IRQ Management
  370. -------------------------------------------------------------------------- */
  371. /*
  372. * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
  373. * Link Devices to move the PIRQs around to minimize sharing.
  374. *
  375. * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
  376. * that the BIOS has already set to active. This is necessary because
  377. * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
  378. * if the BIOS doesn't set a Link Device active, ACPI needs to program it
  379. * even if acpi_irq_nobalance is set.
  380. *
  381. * A tables of penalties avoids directing PCI interrupts to well known
  382. * ISA IRQs. Boot params are available to over-ride the default table:
  383. *
  384. * List interrupts that are free for PCI use.
  385. * acpi_irq_pci=n[,m]
  386. *
  387. * List interrupts that should not be used for PCI:
  388. * acpi_irq_isa=n[,m]
  389. *
  390. * Note that PCI IRQ routers have a list of possible IRQs,
  391. * which may not include the IRQs this table says are available.
  392. *
  393. * Since this heuristic can't tell the difference between a link
  394. * that no device will attach to, vs. a link which may be shared
  395. * by multiple active devices -- it is not optimal.
  396. *
  397. * If interrupt performance is that important, get an IO-APIC system
  398. * with a pin dedicated to each device. Or for that matter, an MSI
  399. * enabled system.
  400. */
  401. #define ACPI_MAX_IRQS 256
  402. #define ACPI_MAX_ISA_IRQ 16
  403. #define PIRQ_PENALTY_PCI_AVAILABLE (0)
  404. #define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
  405. #define PIRQ_PENALTY_PCI_USING (16*16*16)
  406. #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
  407. #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
  408. #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
  409. static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
  410. PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
  411. PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
  412. PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
  413. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
  414. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
  415. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
  416. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
  417. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
  418. PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
  419. PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
  420. PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
  421. PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
  422. PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
  423. PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
  424. PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
  425. PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
  426. /* >IRQ15 */
  427. };
  428. int __init acpi_irq_penalty_init(void)
  429. {
  430. struct acpi_pci_link *link;
  431. int i;
  432. /*
  433. * Update penalties to facilitate IRQ balancing.
  434. */
  435. list_for_each_entry(link, &acpi_link_list, list) {
  436. /*
  437. * reflect the possible and active irqs in the penalty table --
  438. * useful for breaking ties.
  439. */
  440. if (link->irq.possible_count) {
  441. int penalty =
  442. PIRQ_PENALTY_PCI_POSSIBLE /
  443. link->irq.possible_count;
  444. for (i = 0; i < link->irq.possible_count; i++) {
  445. if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
  446. acpi_irq_penalty[link->irq.
  447. possible[i]] +=
  448. penalty;
  449. }
  450. } else if (link->irq.active) {
  451. acpi_irq_penalty[link->irq.active] +=
  452. PIRQ_PENALTY_PCI_POSSIBLE;
  453. }
  454. }
  455. /* Add a penalty for the SCI */
  456. acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
  457. return 0;
  458. }
  459. static int acpi_irq_balance = -1; /* 0: static, 1: balance */
  460. static int acpi_pci_link_allocate(struct acpi_pci_link *link)
  461. {
  462. int irq;
  463. int i;
  464. if (link->irq.initialized) {
  465. if (link->refcnt == 0)
  466. /* This means the link is disabled but initialized */
  467. acpi_pci_link_set(link, link->irq.active);
  468. return 0;
  469. }
  470. /*
  471. * search for active IRQ in list of possible IRQs.
  472. */
  473. for (i = 0; i < link->irq.possible_count; ++i) {
  474. if (link->irq.active == link->irq.possible[i])
  475. break;
  476. }
  477. /*
  478. * forget active IRQ that is not in possible list
  479. */
  480. if (i == link->irq.possible_count) {
  481. if (acpi_strict)
  482. printk(KERN_WARNING PREFIX "_CRS %d not found"
  483. " in _PRS\n", link->irq.active);
  484. link->irq.active = 0;
  485. }
  486. /*
  487. * if active found, use it; else pick entry from end of possible list.
  488. */
  489. if (link->irq.active)
  490. irq = link->irq.active;
  491. else
  492. irq = link->irq.possible[link->irq.possible_count - 1];
  493. if (acpi_irq_balance || !link->irq.active) {
  494. /*
  495. * Select the best IRQ. This is done in reverse to promote
  496. * the use of IRQs 9, 10, 11, and >15.
  497. */
  498. for (i = (link->irq.possible_count - 1); i >= 0; i--) {
  499. if (acpi_irq_penalty[irq] >
  500. acpi_irq_penalty[link->irq.possible[i]])
  501. irq = link->irq.possible[i];
  502. }
  503. }
  504. /* Attempt to enable the link device at this IRQ. */
  505. if (acpi_pci_link_set(link, irq)) {
  506. printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
  507. "Try pci=noacpi or acpi=off\n",
  508. acpi_device_name(link->device),
  509. acpi_device_bid(link->device));
  510. return -ENODEV;
  511. } else {
  512. acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
  513. printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
  514. acpi_device_name(link->device),
  515. acpi_device_bid(link->device), link->irq.active);
  516. }
  517. link->irq.initialized = 1;
  518. return 0;
  519. }
  520. /*
  521. * acpi_pci_link_allocate_irq
  522. * success: return IRQ >= 0
  523. * failure: return -1
  524. */
  525. int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
  526. int *polarity, char **name)
  527. {
  528. int result;
  529. struct acpi_device *device;
  530. struct acpi_pci_link *link;
  531. result = acpi_bus_get_device(handle, &device);
  532. if (result) {
  533. printk(KERN_ERR PREFIX "Invalid link device\n");
  534. return -1;
  535. }
  536. link = acpi_driver_data(device);
  537. if (!link) {
  538. printk(KERN_ERR PREFIX "Invalid link context\n");
  539. return -1;
  540. }
  541. /* TBD: Support multiple index (IRQ) entries per Link Device */
  542. if (index) {
  543. printk(KERN_ERR PREFIX "Invalid index %d\n", index);
  544. return -1;
  545. }
  546. mutex_lock(&acpi_link_lock);
  547. if (acpi_pci_link_allocate(link)) {
  548. mutex_unlock(&acpi_link_lock);
  549. return -1;
  550. }
  551. if (!link->irq.active) {
  552. mutex_unlock(&acpi_link_lock);
  553. printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
  554. return -1;
  555. }
  556. link->refcnt++;
  557. mutex_unlock(&acpi_link_lock);
  558. if (triggering)
  559. *triggering = link->irq.triggering;
  560. if (polarity)
  561. *polarity = link->irq.polarity;
  562. if (name)
  563. *name = acpi_device_bid(link->device);
  564. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  565. "Link %s is referenced\n",
  566. acpi_device_bid(link->device)));
  567. return (link->irq.active);
  568. }
  569. /*
  570. * We don't change link's irq information here. After it is reenabled, we
  571. * continue use the info
  572. */
  573. int acpi_pci_link_free_irq(acpi_handle handle)
  574. {
  575. struct acpi_device *device;
  576. struct acpi_pci_link *link;
  577. acpi_status result;
  578. result = acpi_bus_get_device(handle, &device);
  579. if (result) {
  580. printk(KERN_ERR PREFIX "Invalid link device\n");
  581. return -1;
  582. }
  583. link = acpi_driver_data(device);
  584. if (!link) {
  585. printk(KERN_ERR PREFIX "Invalid link context\n");
  586. return -1;
  587. }
  588. mutex_lock(&acpi_link_lock);
  589. if (!link->irq.initialized) {
  590. mutex_unlock(&acpi_link_lock);
  591. printk(KERN_ERR PREFIX "Link isn't initialized\n");
  592. return -1;
  593. }
  594. #ifdef FUTURE_USE
  595. /*
  596. * The Link reference count allows us to _DISable an unused link
  597. * and suspend time, and set it again on resume.
  598. * However, 2.6.12 still has irq_router.resume
  599. * which blindly restores the link state.
  600. * So we disable the reference count method
  601. * to prevent duplicate acpi_pci_link_set()
  602. * which would harm some systems
  603. */
  604. link->refcnt--;
  605. #endif
  606. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  607. "Link %s is dereferenced\n",
  608. acpi_device_bid(link->device)));
  609. if (link->refcnt == 0)
  610. acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
  611. mutex_unlock(&acpi_link_lock);
  612. return (link->irq.active);
  613. }
  614. /* --------------------------------------------------------------------------
  615. Driver Interface
  616. -------------------------------------------------------------------------- */
  617. static int acpi_pci_link_add(struct acpi_device *device)
  618. {
  619. int result;
  620. struct acpi_pci_link *link;
  621. int i;
  622. int found = 0;
  623. link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
  624. if (!link)
  625. return -ENOMEM;
  626. link->device = device;
  627. strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
  628. strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
  629. device->driver_data = link;
  630. mutex_lock(&acpi_link_lock);
  631. result = acpi_pci_link_get_possible(link);
  632. if (result)
  633. goto end;
  634. /* query and set link->irq.active */
  635. acpi_pci_link_get_current(link);
  636. printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
  637. acpi_device_bid(device));
  638. for (i = 0; i < link->irq.possible_count; i++) {
  639. if (link->irq.active == link->irq.possible[i]) {
  640. printk(" *%d", link->irq.possible[i]);
  641. found = 1;
  642. } else
  643. printk(" %d", link->irq.possible[i]);
  644. }
  645. printk(")");
  646. if (!found)
  647. printk(" *%d", link->irq.active);
  648. if (!link->device->status.enabled)
  649. printk(", disabled.");
  650. printk("\n");
  651. list_add_tail(&link->list, &acpi_link_list);
  652. end:
  653. /* disable all links -- to be activated on use */
  654. acpi_evaluate_object(device->handle, "_DIS", NULL, NULL);
  655. mutex_unlock(&acpi_link_lock);
  656. if (result)
  657. kfree(link);
  658. return result;
  659. }
  660. static int acpi_pci_link_resume(struct acpi_pci_link *link)
  661. {
  662. if (link->refcnt && link->irq.active && link->irq.initialized)
  663. return (acpi_pci_link_set(link, link->irq.active));
  664. return 0;
  665. }
  666. static void irqrouter_resume(void)
  667. {
  668. struct acpi_pci_link *link;
  669. list_for_each_entry(link, &acpi_link_list, list) {
  670. acpi_pci_link_resume(link);
  671. }
  672. }
  673. static int acpi_pci_link_remove(struct acpi_device *device, int type)
  674. {
  675. struct acpi_pci_link *link;
  676. link = acpi_driver_data(device);
  677. mutex_lock(&acpi_link_lock);
  678. list_del(&link->list);
  679. mutex_unlock(&acpi_link_lock);
  680. kfree(link);
  681. return 0;
  682. }
  683. /*
  684. * modify acpi_irq_penalty[] from cmdline
  685. */
  686. static int __init acpi_irq_penalty_update(char *str, int used)
  687. {
  688. int i;
  689. for (i = 0; i < 16; i++) {
  690. int retval;
  691. int irq;
  692. retval = get_option(&str, &irq);
  693. if (!retval)
  694. break; /* no number found */
  695. if (irq < 0)
  696. continue;
  697. if (irq >= ARRAY_SIZE(acpi_irq_penalty))
  698. continue;
  699. if (used)
  700. acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
  701. else
  702. acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
  703. if (retval != 2) /* no next number */
  704. break;
  705. }
  706. return 1;
  707. }
  708. /*
  709. * We'd like PNP to call this routine for the
  710. * single ISA_USED value for each legacy device.
  711. * But instead it calls us with each POSSIBLE setting.
  712. * There is no ISA_POSSIBLE weight, so we simply use
  713. * the (small) PCI_USING penalty.
  714. */
  715. void acpi_penalize_isa_irq(int irq, int active)
  716. {
  717. if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) {
  718. if (active)
  719. acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
  720. else
  721. acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
  722. }
  723. }
  724. /*
  725. * Over-ride default table to reserve additional IRQs for use by ISA
  726. * e.g. acpi_irq_isa=5
  727. * Useful for telling ACPI how not to interfere with your ISA sound card.
  728. */
  729. static int __init acpi_irq_isa(char *str)
  730. {
  731. return acpi_irq_penalty_update(str, 1);
  732. }
  733. __setup("acpi_irq_isa=", acpi_irq_isa);
  734. /*
  735. * Over-ride default table to free additional IRQs for use by PCI
  736. * e.g. acpi_irq_pci=7,15
  737. * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
  738. */
  739. static int __init acpi_irq_pci(char *str)
  740. {
  741. return acpi_irq_penalty_update(str, 0);
  742. }
  743. __setup("acpi_irq_pci=", acpi_irq_pci);
  744. static int __init acpi_irq_nobalance_set(char *str)
  745. {
  746. acpi_irq_balance = 0;
  747. return 1;
  748. }
  749. __setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
  750. static int __init acpi_irq_balance_set(char *str)
  751. {
  752. acpi_irq_balance = 1;
  753. return 1;
  754. }
  755. __setup("acpi_irq_balance", acpi_irq_balance_set);
  756. static struct syscore_ops irqrouter_syscore_ops = {
  757. .resume = irqrouter_resume,
  758. };
  759. static int __init irqrouter_init_ops(void)
  760. {
  761. if (!acpi_disabled && !acpi_noirq)
  762. register_syscore_ops(&irqrouter_syscore_ops);
  763. return 0;
  764. }
  765. device_initcall(irqrouter_init_ops);
  766. static int __init acpi_pci_link_init(void)
  767. {
  768. if (acpi_noirq)
  769. return 0;
  770. if (acpi_irq_balance == -1) {
  771. /* no command line switch: enable balancing in IOAPIC mode */
  772. if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
  773. acpi_irq_balance = 1;
  774. else
  775. acpi_irq_balance = 0;
  776. }
  777. if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
  778. return -ENODEV;
  779. return 0;
  780. }
  781. subsys_initcall(acpi_pci_link_init);