acpiphp_glue.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. /*
  2. * ACPI PCI HotPlug glue functions to ACPI CA subsystem
  3. *
  4. * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
  5. * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
  6. * Copyright (C) 2002,2003 NEC Corporation
  7. * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
  8. * Copyright (C) 2003-2005 Hewlett Packard
  9. * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
  10. * Copyright (C) 2005 Intel Corporation
  11. *
  12. * All rights reserved.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or (at
  17. * your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful, but
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  22. * NON INFRINGEMENT. See the GNU General Public License for more
  23. * details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. *
  29. * Send feedback to <kristen.c.accardi@intel.com>
  30. *
  31. */
  32. /*
  33. * Lifetime rules for pci_dev:
  34. * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
  35. * when the bridge is scanned and it loses a refcount when the bridge
  36. * is removed.
  37. * - When a P2P bridge is present, we elevate the refcount on the subordinate
  38. * bus. It loses the refcount when the the driver unloads.
  39. */
  40. #include <linux/init.h>
  41. #include <linux/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/pci.h>
  44. #include <linux/pci_hotplug.h>
  45. #include <linux/pci-acpi.h>
  46. #include <linux/mutex.h>
  47. #include <linux/slab.h>
  48. #include <linux/acpi.h>
  49. #include "../pci.h"
  50. #include "acpiphp.h"
  51. static LIST_HEAD(bridge_list);
  52. static DEFINE_MUTEX(bridge_mutex);
  53. static DEFINE_MUTEX(acpiphp_context_lock);
  54. #define MY_NAME "acpiphp_glue"
  55. static void handle_hotplug_event(acpi_handle handle, u32 type, void *data);
  56. static void acpiphp_sanitize_bus(struct pci_bus *bus);
  57. static void acpiphp_set_hpp_values(struct pci_bus *bus);
  58. static void hotplug_event_func(acpi_handle handle, u32 type, void *context);
  59. static void free_bridge(struct kref *kref);
  60. /* callback routine to check for the existence of a pci dock device */
  61. static acpi_status
  62. is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
  63. {
  64. int *count = (int *)context;
  65. if (is_dock_device(handle)) {
  66. (*count)++;
  67. return AE_CTRL_TERMINATE;
  68. } else {
  69. return AE_OK;
  70. }
  71. }
  72. static void acpiphp_context_handler(acpi_handle handle, void *context)
  73. {
  74. /* Intentionally empty. */
  75. }
  76. /**
  77. * acpiphp_init_context - Create hotplug context and grab a reference to it.
  78. * @handle: ACPI object handle to create the context for.
  79. *
  80. * Call under acpiphp_context_lock.
  81. */
  82. static struct acpiphp_context *acpiphp_init_context(acpi_handle handle)
  83. {
  84. struct acpiphp_context *context;
  85. acpi_status status;
  86. context = kzalloc(sizeof(*context), GFP_KERNEL);
  87. if (!context)
  88. return NULL;
  89. context->handle = handle;
  90. context->refcount = 1;
  91. status = acpi_attach_data(handle, acpiphp_context_handler, context);
  92. if (ACPI_FAILURE(status)) {
  93. kfree(context);
  94. return NULL;
  95. }
  96. return context;
  97. }
  98. /**
  99. * acpiphp_get_context - Get hotplug context and grab a reference to it.
  100. * @handle: ACPI object handle to get the context for.
  101. *
  102. * Call under acpiphp_context_lock.
  103. */
  104. static struct acpiphp_context *acpiphp_get_context(acpi_handle handle)
  105. {
  106. struct acpiphp_context *context = NULL;
  107. acpi_status status;
  108. void *data;
  109. status = acpi_get_data(handle, acpiphp_context_handler, &data);
  110. if (ACPI_SUCCESS(status)) {
  111. context = data;
  112. context->refcount++;
  113. }
  114. return context;
  115. }
  116. /**
  117. * acpiphp_put_context - Drop a reference to ACPI hotplug context.
  118. * @handle: ACPI object handle to put the context for.
  119. *
  120. * The context object is removed if there are no more references to it.
  121. *
  122. * Call under acpiphp_context_lock.
  123. */
  124. static void acpiphp_put_context(struct acpiphp_context *context)
  125. {
  126. if (--context->refcount)
  127. return;
  128. WARN_ON(context->func || context->bridge);
  129. acpi_detach_data(context->handle, acpiphp_context_handler);
  130. kfree(context);
  131. }
  132. static inline void get_bridge(struct acpiphp_bridge *bridge)
  133. {
  134. kref_get(&bridge->ref);
  135. }
  136. static inline void put_bridge(struct acpiphp_bridge *bridge)
  137. {
  138. kref_put(&bridge->ref, free_bridge);
  139. }
  140. static void free_bridge(struct kref *kref)
  141. {
  142. struct acpiphp_context *context;
  143. struct acpiphp_bridge *bridge;
  144. struct acpiphp_slot *slot, *next;
  145. struct acpiphp_func *func, *tmp;
  146. mutex_lock(&acpiphp_context_lock);
  147. bridge = container_of(kref, struct acpiphp_bridge, ref);
  148. list_for_each_entry_safe(slot, next, &bridge->slots, node) {
  149. list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) {
  150. context = func->context;
  151. context->func = NULL;
  152. acpiphp_put_context(context);
  153. kfree(func);
  154. }
  155. kfree(slot);
  156. }
  157. context = bridge->context;
  158. /* Release the reference acquired by acpiphp_enumerate_slots(). */
  159. if (context->handler_for_func)
  160. put_bridge(bridge->func->slot->bridge);
  161. put_device(&bridge->pci_bus->dev);
  162. pci_dev_put(bridge->pci_dev);
  163. context->bridge = NULL;
  164. acpiphp_put_context(context);
  165. kfree(bridge);
  166. mutex_unlock(&acpiphp_context_lock);
  167. }
  168. /*
  169. * the _DCK method can do funny things... and sometimes not
  170. * hah-hah funny.
  171. *
  172. * TBD - figure out a way to only call fixups for
  173. * systems that require them.
  174. */
  175. static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
  176. {
  177. struct acpiphp_func *func = data;
  178. struct pci_bus *bus = func->slot->bridge->pci_bus;
  179. u32 buses;
  180. if (!bus->self)
  181. return;
  182. /* fixup bad _DCK function that rewrites
  183. * secondary bridge on slot
  184. */
  185. pci_read_config_dword(bus->self,
  186. PCI_PRIMARY_BUS,
  187. &buses);
  188. if (((buses >> 8) & 0xff) != bus->busn_res.start) {
  189. buses = (buses & 0xff000000)
  190. | ((unsigned int)(bus->primary) << 0)
  191. | ((unsigned int)(bus->busn_res.start) << 8)
  192. | ((unsigned int)(bus->busn_res.end) << 16);
  193. pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
  194. }
  195. }
  196. static const struct acpi_dock_ops acpiphp_dock_ops = {
  197. .fixup = post_dock_fixups,
  198. .handler = hotplug_event_func,
  199. };
  200. /* Check whether the PCI device is managed by native PCIe hotplug driver */
  201. static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
  202. {
  203. u32 reg32;
  204. acpi_handle tmp;
  205. struct acpi_pci_root *root;
  206. /* Check whether the PCIe port supports native PCIe hotplug */
  207. if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, &reg32))
  208. return false;
  209. if (!(reg32 & PCI_EXP_SLTCAP_HPC))
  210. return false;
  211. /*
  212. * Check whether native PCIe hotplug has been enabled for
  213. * this PCIe hierarchy.
  214. */
  215. tmp = acpi_find_root_bridge_handle(pdev);
  216. if (!tmp)
  217. return false;
  218. root = acpi_pci_find_root(tmp);
  219. if (!root)
  220. return false;
  221. if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
  222. return false;
  223. return true;
  224. }
  225. static void acpiphp_dock_init(void *data)
  226. {
  227. struct acpiphp_func *func = data;
  228. get_bridge(func->slot->bridge);
  229. }
  230. static void acpiphp_dock_release(void *data)
  231. {
  232. struct acpiphp_func *func = data;
  233. put_bridge(func->slot->bridge);
  234. }
  235. /* callback routine to register each ACPI PCI slot object */
  236. static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data,
  237. void **rv)
  238. {
  239. struct acpiphp_bridge *bridge = data;
  240. struct acpiphp_context *context;
  241. struct acpiphp_slot *slot;
  242. struct acpiphp_func *newfunc;
  243. acpi_status status = AE_OK;
  244. unsigned long long adr, sun;
  245. int device, function, retval, found = 0;
  246. struct pci_bus *pbus = bridge->pci_bus;
  247. struct pci_dev *pdev;
  248. u32 val;
  249. if (!acpi_pci_check_ejectable(pbus, handle) && !is_dock_device(handle))
  250. return AE_OK;
  251. status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
  252. if (ACPI_FAILURE(status)) {
  253. warn("can't evaluate _ADR (%#x)\n", status);
  254. return AE_OK;
  255. }
  256. device = (adr >> 16) & 0xffff;
  257. function = adr & 0xffff;
  258. pdev = bridge->pci_dev;
  259. if (pdev && device_is_managed_by_native_pciehp(pdev))
  260. return AE_OK;
  261. newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
  262. if (!newfunc)
  263. return AE_NO_MEMORY;
  264. newfunc->handle = handle;
  265. newfunc->function = function;
  266. mutex_lock(&acpiphp_context_lock);
  267. context = acpiphp_init_context(handle);
  268. if (!context) {
  269. mutex_unlock(&acpiphp_context_lock);
  270. acpi_handle_err(handle, "No hotplug context\n");
  271. kfree(newfunc);
  272. return AE_NOT_EXIST;
  273. }
  274. newfunc->context = context;
  275. context->func = newfunc;
  276. mutex_unlock(&acpiphp_context_lock);
  277. if (acpi_has_method(handle, "_EJ0"))
  278. newfunc->flags = FUNC_HAS_EJ0;
  279. if (acpi_has_method(handle, "_STA"))
  280. newfunc->flags |= FUNC_HAS_STA;
  281. if (acpi_has_method(handle, "_PS0"))
  282. newfunc->flags |= FUNC_HAS_PS0;
  283. if (acpi_has_method(handle, "_PS3"))
  284. newfunc->flags |= FUNC_HAS_PS3;
  285. if (acpi_has_method(handle, "_DCK"))
  286. newfunc->flags |= FUNC_HAS_DCK;
  287. status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
  288. if (ACPI_FAILURE(status)) {
  289. /*
  290. * use the count of the number of slots we've found
  291. * for the number of the slot
  292. */
  293. sun = bridge->nr_slots+1;
  294. }
  295. /* search for objects that share the same slot */
  296. list_for_each_entry(slot, &bridge->slots, node)
  297. if (slot->device == device) {
  298. if (slot->sun != sun)
  299. warn("sibling found, but _SUN doesn't match!\n");
  300. found = 1;
  301. break;
  302. }
  303. if (!found) {
  304. slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
  305. if (!slot) {
  306. status = AE_NO_MEMORY;
  307. goto err_out;
  308. }
  309. slot->bridge = bridge;
  310. slot->device = device;
  311. slot->sun = sun;
  312. INIT_LIST_HEAD(&slot->funcs);
  313. mutex_init(&slot->crit_sect);
  314. mutex_lock(&bridge_mutex);
  315. list_add_tail(&slot->node, &bridge->slots);
  316. mutex_unlock(&bridge_mutex);
  317. bridge->nr_slots++;
  318. dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
  319. slot->sun, pci_domain_nr(pbus), pbus->number, device);
  320. retval = acpiphp_register_hotplug_slot(slot);
  321. if (retval) {
  322. if (retval == -EBUSY)
  323. warn("Slot %llu already registered by another "
  324. "hotplug driver\n", slot->sun);
  325. else
  326. warn("acpiphp_register_hotplug_slot failed "
  327. "(err code = 0x%x)\n", retval);
  328. status = AE_OK;
  329. goto err;
  330. }
  331. }
  332. newfunc->slot = slot;
  333. mutex_lock(&bridge_mutex);
  334. list_add_tail(&newfunc->sibling, &slot->funcs);
  335. mutex_unlock(&bridge_mutex);
  336. if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
  337. &val, 60*1000))
  338. slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
  339. if (is_dock_device(handle)) {
  340. /* we don't want to call this device's _EJ0
  341. * because we want the dock notify handler
  342. * to call it after it calls _DCK
  343. */
  344. newfunc->flags &= ~FUNC_HAS_EJ0;
  345. if (register_hotplug_dock_device(handle,
  346. &acpiphp_dock_ops, newfunc,
  347. acpiphp_dock_init, acpiphp_dock_release))
  348. dbg("failed to register dock device\n");
  349. }
  350. /* install notify handler */
  351. if (!(newfunc->flags & FUNC_HAS_DCK)) {
  352. status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
  353. handle_hotplug_event,
  354. context);
  355. if (ACPI_SUCCESS(status))
  356. context->handler_for_func = true;
  357. else
  358. err("failed to register interrupt notify handler\n");
  359. }
  360. return AE_OK;
  361. err:
  362. bridge->nr_slots--;
  363. mutex_lock(&bridge_mutex);
  364. list_del(&slot->node);
  365. mutex_unlock(&bridge_mutex);
  366. kfree(slot);
  367. err_out:
  368. mutex_lock(&acpiphp_context_lock);
  369. context->func = NULL;
  370. acpiphp_put_context(context);
  371. mutex_unlock(&acpiphp_context_lock);
  372. kfree(newfunc);
  373. return status;
  374. }
  375. /* see if it's worth looking at this bridge */
  376. static int detect_ejectable_slots(acpi_handle handle)
  377. {
  378. int found = acpi_pci_detect_ejectable(handle);
  379. if (!found) {
  380. acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
  381. is_pci_dock_device, NULL, (void *)&found, NULL);
  382. }
  383. return found;
  384. }
  385. static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
  386. {
  387. struct acpiphp_context *context;
  388. struct acpiphp_bridge *bridge = NULL;
  389. mutex_lock(&acpiphp_context_lock);
  390. context = acpiphp_get_context(handle);
  391. if (context) {
  392. bridge = context->bridge;
  393. if (bridge)
  394. get_bridge(bridge);
  395. acpiphp_put_context(context);
  396. }
  397. mutex_unlock(&acpiphp_context_lock);
  398. return bridge;
  399. }
  400. static void cleanup_bridge(struct acpiphp_bridge *bridge)
  401. {
  402. struct acpiphp_slot *slot;
  403. struct acpiphp_func *func;
  404. acpi_status status;
  405. acpi_handle handle = bridge->handle;
  406. if (!bridge->context->handler_for_func) {
  407. status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
  408. handle_hotplug_event);
  409. if (ACPI_FAILURE(status))
  410. err("failed to remove notify handler\n");
  411. }
  412. list_for_each_entry(slot, &bridge->slots, node) {
  413. list_for_each_entry(func, &slot->funcs, sibling) {
  414. if (is_dock_device(func->handle)) {
  415. unregister_hotplug_dock_device(func->handle);
  416. }
  417. if (!(func->flags & FUNC_HAS_DCK)) {
  418. func->context->handler_for_func = false;
  419. status = acpi_remove_notify_handler(func->handle,
  420. ACPI_SYSTEM_NOTIFY,
  421. handle_hotplug_event);
  422. if (ACPI_FAILURE(status))
  423. err("failed to remove notify handler\n");
  424. }
  425. }
  426. acpiphp_unregister_hotplug_slot(slot);
  427. }
  428. mutex_lock(&bridge_mutex);
  429. list_del(&bridge->list);
  430. mutex_unlock(&bridge_mutex);
  431. }
  432. static int power_on_slot(struct acpiphp_slot *slot)
  433. {
  434. acpi_status status;
  435. struct acpiphp_func *func;
  436. int retval = 0;
  437. /* if already enabled, just skip */
  438. if (slot->flags & SLOT_POWEREDON)
  439. goto err_exit;
  440. list_for_each_entry(func, &slot->funcs, sibling) {
  441. if (func->flags & FUNC_HAS_PS0) {
  442. dbg("%s: executing _PS0\n", __func__);
  443. status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
  444. if (ACPI_FAILURE(status)) {
  445. warn("%s: _PS0 failed\n", __func__);
  446. retval = -1;
  447. goto err_exit;
  448. } else
  449. break;
  450. }
  451. }
  452. /* TBD: evaluate _STA to check if the slot is enabled */
  453. slot->flags |= SLOT_POWEREDON;
  454. err_exit:
  455. return retval;
  456. }
  457. static int power_off_slot(struct acpiphp_slot *slot)
  458. {
  459. acpi_status status;
  460. struct acpiphp_func *func;
  461. int retval = 0;
  462. /* if already disabled, just skip */
  463. if ((slot->flags & SLOT_POWEREDON) == 0)
  464. goto err_exit;
  465. list_for_each_entry(func, &slot->funcs, sibling) {
  466. if (func->flags & FUNC_HAS_PS3) {
  467. status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
  468. if (ACPI_FAILURE(status)) {
  469. warn("%s: _PS3 failed\n", __func__);
  470. retval = -1;
  471. goto err_exit;
  472. } else
  473. break;
  474. }
  475. }
  476. /* TBD: evaluate _STA to check if the slot is disabled */
  477. slot->flags &= (~SLOT_POWEREDON);
  478. err_exit:
  479. return retval;
  480. }
  481. /**
  482. * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
  483. * @bus: bus to start search with
  484. */
  485. static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
  486. {
  487. struct list_head *tmp;
  488. unsigned char max, n;
  489. /*
  490. * pci_bus_max_busnr will return the highest
  491. * reserved busnr for all these children.
  492. * that is equivalent to the bus->subordinate
  493. * value. We don't want to use the parent's
  494. * bus->subordinate value because it could have
  495. * padding in it.
  496. */
  497. max = bus->busn_res.start;
  498. list_for_each(tmp, &bus->children) {
  499. n = pci_bus_max_busnr(pci_bus_b(tmp));
  500. if (n > max)
  501. max = n;
  502. }
  503. return max;
  504. }
  505. /**
  506. * acpiphp_bus_add - add a new bus to acpi subsystem
  507. * @func: acpiphp_func of the bridge
  508. */
  509. static int acpiphp_bus_add(struct acpiphp_func *func)
  510. {
  511. struct acpi_device *device;
  512. int ret_val;
  513. if (!acpi_bus_get_device(func->handle, &device)) {
  514. dbg("bus exists... trim\n");
  515. /* this shouldn't be in here, so remove
  516. * the bus then re-add it...
  517. */
  518. acpi_bus_trim(device);
  519. }
  520. ret_val = acpi_bus_scan(func->handle);
  521. if (!ret_val)
  522. ret_val = acpi_bus_get_device(func->handle, &device);
  523. if (ret_val)
  524. dbg("error adding bus, %x\n", -ret_val);
  525. return ret_val;
  526. }
  527. /**
  528. * acpiphp_bus_trim - trim a bus from acpi subsystem
  529. * @handle: handle to acpi namespace
  530. */
  531. static int acpiphp_bus_trim(acpi_handle handle)
  532. {
  533. struct acpi_device *device;
  534. int retval;
  535. retval = acpi_bus_get_device(handle, &device);
  536. if (retval) {
  537. dbg("acpi_device not found\n");
  538. return retval;
  539. }
  540. acpi_bus_trim(device);
  541. return 0;
  542. }
  543. static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
  544. {
  545. struct acpiphp_func *func;
  546. union acpi_object params[2];
  547. struct acpi_object_list arg_list;
  548. list_for_each_entry(func, &slot->funcs, sibling) {
  549. arg_list.count = 2;
  550. arg_list.pointer = params;
  551. params[0].type = ACPI_TYPE_INTEGER;
  552. params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
  553. params[1].type = ACPI_TYPE_INTEGER;
  554. params[1].integer.value = 1;
  555. /* _REG is optional, we don't care about if there is failure */
  556. acpi_evaluate_object(func->handle, "_REG", &arg_list, NULL);
  557. }
  558. }
  559. static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
  560. {
  561. struct acpiphp_func *func;
  562. if (!dev->subordinate)
  563. return;
  564. /* quirk, or pcie could set it already */
  565. if (dev->is_hotplug_bridge)
  566. return;
  567. if (PCI_SLOT(dev->devfn) != slot->device)
  568. return;
  569. list_for_each_entry(func, &slot->funcs, sibling) {
  570. if (PCI_FUNC(dev->devfn) == func->function) {
  571. /* check if this bridge has ejectable slots */
  572. if ((detect_ejectable_slots(func->handle) > 0))
  573. dev->is_hotplug_bridge = 1;
  574. break;
  575. }
  576. }
  577. }
  578. /**
  579. * enable_device - enable, configure a slot
  580. * @slot: slot to be enabled
  581. *
  582. * This function should be called per *physical slot*,
  583. * not per each slot object in ACPI namespace.
  584. */
  585. static int __ref enable_device(struct acpiphp_slot *slot)
  586. {
  587. struct pci_dev *dev;
  588. struct pci_bus *bus = slot->bridge->pci_bus;
  589. struct acpiphp_func *func;
  590. int num, max, pass;
  591. LIST_HEAD(add_list);
  592. if (slot->flags & SLOT_ENABLED)
  593. goto err_exit;
  594. list_for_each_entry(func, &slot->funcs, sibling)
  595. acpiphp_bus_add(func);
  596. num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
  597. if (num == 0) {
  598. /* Maybe only part of funcs are added. */
  599. dbg("No new device found\n");
  600. goto err_exit;
  601. }
  602. max = acpiphp_max_busnr(bus);
  603. for (pass = 0; pass < 2; pass++) {
  604. list_for_each_entry(dev, &bus->devices, bus_list) {
  605. if (PCI_SLOT(dev->devfn) != slot->device)
  606. continue;
  607. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  608. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
  609. max = pci_scan_bridge(bus, dev, max, pass);
  610. if (pass && dev->subordinate) {
  611. check_hotplug_bridge(slot, dev);
  612. pcibios_resource_survey_bus(dev->subordinate);
  613. __pci_bus_size_bridges(dev->subordinate,
  614. &add_list);
  615. }
  616. }
  617. }
  618. }
  619. __pci_bus_assign_resources(bus, &add_list, NULL);
  620. acpiphp_sanitize_bus(bus);
  621. acpiphp_set_hpp_values(bus);
  622. acpiphp_set_acpi_region(slot);
  623. pci_enable_bridges(bus);
  624. list_for_each_entry(dev, &bus->devices, bus_list) {
  625. /* Assume that newly added devices are powered on already. */
  626. if (!dev->is_added)
  627. dev->current_state = PCI_D0;
  628. }
  629. pci_bus_add_devices(bus);
  630. slot->flags |= SLOT_ENABLED;
  631. list_for_each_entry(func, &slot->funcs, sibling) {
  632. dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
  633. func->function));
  634. if (!dev) {
  635. /* Do not set SLOT_ENABLED flag if some funcs
  636. are not added. */
  637. slot->flags &= (~SLOT_ENABLED);
  638. continue;
  639. }
  640. }
  641. err_exit:
  642. return 0;
  643. }
  644. /* return first device in slot, acquiring a reference on it */
  645. static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
  646. {
  647. struct pci_bus *bus = slot->bridge->pci_bus;
  648. struct pci_dev *dev;
  649. struct pci_dev *ret = NULL;
  650. down_read(&pci_bus_sem);
  651. list_for_each_entry(dev, &bus->devices, bus_list)
  652. if (PCI_SLOT(dev->devfn) == slot->device) {
  653. ret = pci_dev_get(dev);
  654. break;
  655. }
  656. up_read(&pci_bus_sem);
  657. return ret;
  658. }
  659. /**
  660. * disable_device - disable a slot
  661. * @slot: ACPI PHP slot
  662. */
  663. static int disable_device(struct acpiphp_slot *slot)
  664. {
  665. struct acpiphp_func *func;
  666. struct pci_dev *pdev;
  667. /*
  668. * enable_device() enumerates all functions in this device via
  669. * pci_scan_slot(), whether they have associated ACPI hotplug
  670. * methods (_EJ0, etc.) or not. Therefore, we remove all functions
  671. * here.
  672. */
  673. while ((pdev = dev_in_slot(slot))) {
  674. pci_stop_and_remove_bus_device(pdev);
  675. pci_dev_put(pdev);
  676. }
  677. list_for_each_entry(func, &slot->funcs, sibling) {
  678. acpiphp_bus_trim(func->handle);
  679. }
  680. slot->flags &= (~SLOT_ENABLED);
  681. return 0;
  682. }
  683. /**
  684. * get_slot_status - get ACPI slot status
  685. * @slot: ACPI PHP slot
  686. *
  687. * If a slot has _STA for each function and if any one of them
  688. * returned non-zero status, return it.
  689. *
  690. * If a slot doesn't have _STA and if any one of its functions'
  691. * configuration space is configured, return 0x0f as a _STA.
  692. *
  693. * Otherwise return 0.
  694. */
  695. static unsigned int get_slot_status(struct acpiphp_slot *slot)
  696. {
  697. acpi_status status;
  698. unsigned long long sta = 0;
  699. u32 dvid;
  700. struct acpiphp_func *func;
  701. list_for_each_entry(func, &slot->funcs, sibling) {
  702. if (func->flags & FUNC_HAS_STA) {
  703. status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
  704. if (ACPI_SUCCESS(status) && sta)
  705. break;
  706. } else {
  707. pci_bus_read_config_dword(slot->bridge->pci_bus,
  708. PCI_DEVFN(slot->device,
  709. func->function),
  710. PCI_VENDOR_ID, &dvid);
  711. if (dvid != 0xffffffff) {
  712. sta = ACPI_STA_ALL;
  713. break;
  714. }
  715. }
  716. }
  717. return (unsigned int)sta;
  718. }
  719. /**
  720. * acpiphp_eject_slot - physically eject the slot
  721. * @slot: ACPI PHP slot
  722. */
  723. int acpiphp_eject_slot(struct acpiphp_slot *slot)
  724. {
  725. struct acpiphp_func *func;
  726. list_for_each_entry(func, &slot->funcs, sibling) {
  727. /* We don't want to call _EJ0 on non-existing functions. */
  728. if ((func->flags & FUNC_HAS_EJ0)) {
  729. if (ACPI_FAILURE(acpi_evaluate_ej0(func->handle)))
  730. return -1;
  731. else
  732. break;
  733. }
  734. }
  735. return 0;
  736. }
  737. /**
  738. * acpiphp_check_bridge - re-enumerate devices
  739. * @bridge: where to begin re-enumeration
  740. *
  741. * Iterate over all slots under this bridge and make sure that if a
  742. * card is present they are enabled, and if not they are disabled.
  743. */
  744. static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
  745. {
  746. struct acpiphp_slot *slot;
  747. int retval = 0;
  748. int enabled, disabled;
  749. enabled = disabled = 0;
  750. list_for_each_entry(slot, &bridge->slots, node) {
  751. unsigned int status = get_slot_status(slot);
  752. if (slot->flags & SLOT_ENABLED) {
  753. if (status == ACPI_STA_ALL)
  754. continue;
  755. retval = acpiphp_disable_slot(slot);
  756. if (retval) {
  757. err("Error occurred in disabling\n");
  758. goto err_exit;
  759. } else {
  760. acpiphp_eject_slot(slot);
  761. }
  762. disabled++;
  763. } else {
  764. if (status != ACPI_STA_ALL)
  765. continue;
  766. retval = acpiphp_enable_slot(slot);
  767. if (retval) {
  768. err("Error occurred in enabling\n");
  769. goto err_exit;
  770. }
  771. enabled++;
  772. }
  773. }
  774. dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled);
  775. err_exit:
  776. return retval;
  777. }
  778. static void acpiphp_set_hpp_values(struct pci_bus *bus)
  779. {
  780. struct pci_dev *dev;
  781. list_for_each_entry(dev, &bus->devices, bus_list)
  782. pci_configure_slot(dev);
  783. }
  784. /*
  785. * Remove devices for which we could not assign resources, call
  786. * arch specific code to fix-up the bus
  787. */
  788. static void acpiphp_sanitize_bus(struct pci_bus *bus)
  789. {
  790. struct pci_dev *dev, *tmp;
  791. int i;
  792. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
  793. list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
  794. for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
  795. struct resource *res = &dev->resource[i];
  796. if ((res->flags & type_mask) && !res->start &&
  797. res->end) {
  798. /* Could not assign a required resources
  799. * for this device, remove it */
  800. pci_stop_and_remove_bus_device(dev);
  801. break;
  802. }
  803. }
  804. }
  805. }
  806. /*
  807. * ACPI event handlers
  808. */
  809. static acpi_status
  810. check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
  811. {
  812. struct acpiphp_bridge *bridge;
  813. char objname[64];
  814. struct acpi_buffer buffer = { .length = sizeof(objname),
  815. .pointer = objname };
  816. bridge = acpiphp_handle_to_bridge(handle);
  817. if (bridge) {
  818. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  819. dbg("%s: re-enumerating slots under %s\n",
  820. __func__, objname);
  821. acpiphp_check_bridge(bridge);
  822. put_bridge(bridge);
  823. }
  824. return AE_OK ;
  825. }
  826. void acpiphp_check_host_bridge(acpi_handle handle)
  827. {
  828. struct acpiphp_bridge *bridge;
  829. bridge = acpiphp_handle_to_bridge(handle);
  830. if (bridge) {
  831. acpiphp_check_bridge(bridge);
  832. put_bridge(bridge);
  833. }
  834. acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
  835. ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
  836. }
  837. static void _handle_hotplug_event_bridge(struct work_struct *work)
  838. {
  839. struct acpiphp_context *context;
  840. struct acpiphp_bridge *bridge;
  841. char objname[64];
  842. struct acpi_buffer buffer = { .length = sizeof(objname),
  843. .pointer = objname };
  844. struct acpi_hp_work *hp_work;
  845. acpi_handle handle;
  846. u32 type;
  847. hp_work = container_of(work, struct acpi_hp_work, work);
  848. handle = hp_work->handle;
  849. type = hp_work->type;
  850. context = hp_work->context;
  851. bridge = context->bridge;
  852. acpi_scan_lock_acquire();
  853. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  854. switch (type) {
  855. case ACPI_NOTIFY_BUS_CHECK:
  856. /* bus re-enumerate */
  857. dbg("%s: Bus check notify on %s\n", __func__, objname);
  858. dbg("%s: re-enumerating slots under %s\n", __func__, objname);
  859. acpiphp_check_bridge(bridge);
  860. acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
  861. ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
  862. break;
  863. case ACPI_NOTIFY_DEVICE_CHECK:
  864. /* device check */
  865. dbg("%s: Device check notify on %s\n", __func__, objname);
  866. acpiphp_check_bridge(bridge);
  867. break;
  868. case ACPI_NOTIFY_DEVICE_WAKE:
  869. /* wake event */
  870. dbg("%s: Device wake notify on %s\n", __func__, objname);
  871. break;
  872. case ACPI_NOTIFY_EJECT_REQUEST:
  873. /* request device eject */
  874. dbg("%s: Device eject notify on %s\n", __func__, objname);
  875. if ((bridge->flags & BRIDGE_HAS_EJ0) && bridge->func) {
  876. struct acpiphp_slot *slot;
  877. slot = bridge->func->slot;
  878. if (!acpiphp_disable_slot(slot))
  879. acpiphp_eject_slot(slot);
  880. }
  881. break;
  882. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  883. printk(KERN_ERR "Device %s cannot be configured due"
  884. " to a frequency mismatch\n", objname);
  885. break;
  886. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  887. printk(KERN_ERR "Device %s cannot be configured due"
  888. " to a bus mode mismatch\n", objname);
  889. break;
  890. case ACPI_NOTIFY_POWER_FAULT:
  891. printk(KERN_ERR "Device %s has suffered a power fault\n",
  892. objname);
  893. break;
  894. default:
  895. warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
  896. break;
  897. }
  898. acpi_scan_lock_release();
  899. kfree(hp_work); /* allocated in handle_hotplug_event_bridge */
  900. put_bridge(bridge);
  901. }
  902. static void hotplug_event_func(acpi_handle handle, u32 type, void *context)
  903. {
  904. struct acpiphp_func *func = context;
  905. char objname[64];
  906. struct acpi_buffer buffer = { .length = sizeof(objname),
  907. .pointer = objname };
  908. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  909. switch (type) {
  910. case ACPI_NOTIFY_BUS_CHECK:
  911. /* bus re-enumerate */
  912. dbg("%s: Bus check notify on %s\n", __func__, objname);
  913. acpiphp_enable_slot(func->slot);
  914. break;
  915. case ACPI_NOTIFY_DEVICE_CHECK:
  916. /* device check : re-enumerate from parent bus */
  917. dbg("%s: Device check notify on %s\n", __func__, objname);
  918. acpiphp_check_bridge(func->slot->bridge);
  919. break;
  920. case ACPI_NOTIFY_DEVICE_WAKE:
  921. /* wake event */
  922. dbg("%s: Device wake notify on %s\n", __func__, objname);
  923. break;
  924. case ACPI_NOTIFY_EJECT_REQUEST:
  925. /* request device eject */
  926. dbg("%s: Device eject notify on %s\n", __func__, objname);
  927. if (!(acpiphp_disable_slot(func->slot)))
  928. acpiphp_eject_slot(func->slot);
  929. break;
  930. default:
  931. warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
  932. break;
  933. }
  934. }
  935. static void _handle_hotplug_event_func(struct work_struct *work)
  936. {
  937. struct acpiphp_context *context;
  938. struct acpi_hp_work *hp_work;
  939. hp_work = container_of(work, struct acpi_hp_work, work);
  940. context = hp_work->context;
  941. acpi_scan_lock_acquire();
  942. hotplug_event_func(hp_work->handle, hp_work->type, context->func);
  943. acpi_scan_lock_release();
  944. kfree(hp_work); /* allocated in handle_hotplug_event_func */
  945. put_bridge(context->func->slot->bridge);
  946. }
  947. /**
  948. * handle_hotplug_event - handle ACPI hotplug event
  949. * @handle: Notify()'ed acpi_handle
  950. * @type: Notify code
  951. * @data: pointer to acpiphp_context structure
  952. *
  953. * Handles ACPI event notification on slots.
  954. */
  955. static void handle_hotplug_event(acpi_handle handle, u32 type, void *data)
  956. {
  957. struct acpiphp_context *context;
  958. void (*work_func)(struct work_struct *work) = NULL;
  959. mutex_lock(&acpiphp_context_lock);
  960. context = acpiphp_get_context(handle);
  961. if (context) {
  962. if (context->bridge) {
  963. get_bridge(context->bridge);
  964. work_func = _handle_hotplug_event_bridge;
  965. } else if (context->func) {
  966. get_bridge(context->func->slot->bridge);
  967. work_func = _handle_hotplug_event_func;
  968. }
  969. acpiphp_put_context(context);
  970. }
  971. mutex_unlock(&acpiphp_context_lock);
  972. /*
  973. * Currently the code adds all hotplug events to the kacpid_wq
  974. * queue when it should add hotplug events to the kacpi_hotplug_wq.
  975. * The proper way to fix this is to reorganize the code so that
  976. * drivers (dock, etc.) do not call acpi_os_execute(), etc.
  977. * For now just re-add this work to the kacpi_hotplug_wq so we
  978. * don't deadlock on hotplug actions.
  979. */
  980. if (work_func)
  981. alloc_acpi_hp_work(handle, type, context, work_func);
  982. }
  983. /*
  984. * Create hotplug slots for the PCI bus.
  985. * It should always return 0 to avoid skipping following notifiers.
  986. */
  987. void acpiphp_enumerate_slots(struct pci_bus *bus)
  988. {
  989. struct acpiphp_context *context;
  990. struct acpiphp_bridge *bridge;
  991. acpi_handle handle;
  992. acpi_status status;
  993. if (acpiphp_disabled)
  994. return;
  995. handle = ACPI_HANDLE(bus->bridge);
  996. if (!handle || detect_ejectable_slots(handle) <= 0)
  997. return;
  998. bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
  999. if (!bridge) {
  1000. acpi_handle_err(handle, "No memory for bridge object\n");
  1001. return;
  1002. }
  1003. INIT_LIST_HEAD(&bridge->slots);
  1004. kref_init(&bridge->ref);
  1005. bridge->handle = handle;
  1006. bridge->pci_dev = pci_dev_get(bus->self);
  1007. bridge->pci_bus = bus;
  1008. mutex_lock(&acpiphp_context_lock);
  1009. context = acpiphp_get_context(handle);
  1010. if (!context) {
  1011. context = acpiphp_init_context(handle);
  1012. if (!context) {
  1013. mutex_unlock(&acpiphp_context_lock);
  1014. acpi_handle_err(handle, "No hotplug context\n");
  1015. kfree(bridge);
  1016. return;
  1017. }
  1018. }
  1019. bridge->context = context;
  1020. context->bridge = bridge;
  1021. mutex_unlock(&acpiphp_context_lock);
  1022. /*
  1023. * Grab a ref to the subordinate PCI bus in case the bus is
  1024. * removed via PCI core logical hotplug. The ref pins the bus
  1025. * (which we access during module unload).
  1026. */
  1027. get_device(&bus->dev);
  1028. /* must be added to the list prior to calling register_slot */
  1029. mutex_lock(&bridge_mutex);
  1030. list_add(&bridge->list, &bridge_list);
  1031. mutex_unlock(&bridge_mutex);
  1032. /* register all slot objects under this bridge */
  1033. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, 1,
  1034. register_slot, NULL, bridge, NULL);
  1035. if (ACPI_FAILURE(status)) {
  1036. acpi_handle_err(bridge->handle, "failed to register slots\n");
  1037. goto err;
  1038. }
  1039. if (pci_is_root_bus(bridge->pci_bus))
  1040. return;
  1041. if (acpi_has_method(bridge->handle, "_EJ0")) {
  1042. dbg("found ejectable p2p bridge\n");
  1043. bridge->flags |= BRIDGE_HAS_EJ0;
  1044. }
  1045. if (context->handler_for_func) {
  1046. /* Notify handler already installed. */
  1047. bridge->func = context->func;
  1048. get_bridge(context->func->slot->bridge);
  1049. return;
  1050. }
  1051. /* install notify handler for P2P bridges */
  1052. status = acpi_install_notify_handler(bridge->handle, ACPI_SYSTEM_NOTIFY,
  1053. handle_hotplug_event, NULL);
  1054. if (ACPI_SUCCESS(status))
  1055. return;
  1056. acpi_handle_err(bridge->handle, "failed to register notify handler\n");
  1057. err:
  1058. cleanup_bridge(bridge);
  1059. put_bridge(bridge);
  1060. }
  1061. /* Destroy hotplug slots associated with the PCI bus */
  1062. void acpiphp_remove_slots(struct pci_bus *bus)
  1063. {
  1064. struct acpiphp_bridge *bridge, *tmp;
  1065. if (acpiphp_disabled)
  1066. return;
  1067. list_for_each_entry_safe(bridge, tmp, &bridge_list, list)
  1068. if (bridge->pci_bus == bus) {
  1069. cleanup_bridge(bridge);
  1070. put_bridge(bridge);
  1071. break;
  1072. }
  1073. }
  1074. /**
  1075. * acpiphp_enable_slot - power on slot
  1076. * @slot: ACPI PHP slot
  1077. */
  1078. int acpiphp_enable_slot(struct acpiphp_slot *slot)
  1079. {
  1080. int retval;
  1081. mutex_lock(&slot->crit_sect);
  1082. /* wake up all functions */
  1083. retval = power_on_slot(slot);
  1084. if (retval)
  1085. goto err_exit;
  1086. if (get_slot_status(slot) == ACPI_STA_ALL) {
  1087. /* configure all functions */
  1088. retval = enable_device(slot);
  1089. if (retval)
  1090. power_off_slot(slot);
  1091. } else {
  1092. dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__);
  1093. power_off_slot(slot);
  1094. }
  1095. err_exit:
  1096. mutex_unlock(&slot->crit_sect);
  1097. return retval;
  1098. }
  1099. /**
  1100. * acpiphp_disable_slot - power off slot
  1101. * @slot: ACPI PHP slot
  1102. */
  1103. int acpiphp_disable_slot(struct acpiphp_slot *slot)
  1104. {
  1105. int retval = 0;
  1106. mutex_lock(&slot->crit_sect);
  1107. /* unconfigure all functions */
  1108. retval = disable_device(slot);
  1109. if (retval)
  1110. goto err_exit;
  1111. /* power off all functions */
  1112. retval = power_off_slot(slot);
  1113. if (retval)
  1114. goto err_exit;
  1115. err_exit:
  1116. mutex_unlock(&slot->crit_sect);
  1117. return retval;
  1118. }
  1119. /*
  1120. * slot enabled: 1
  1121. * slot disabled: 0
  1122. */
  1123. u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
  1124. {
  1125. return (slot->flags & SLOT_POWEREDON);
  1126. }
  1127. /*
  1128. * latch open: 1
  1129. * latch closed: 0
  1130. */
  1131. u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
  1132. {
  1133. unsigned int sta;
  1134. sta = get_slot_status(slot);
  1135. return (sta & ACPI_STA_DEVICE_UI) ? 0 : 1;
  1136. }
  1137. /*
  1138. * adapter presence : 1
  1139. * absence : 0
  1140. */
  1141. u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
  1142. {
  1143. unsigned int sta;
  1144. sta = get_slot_status(slot);
  1145. return (sta == 0) ? 0 : 1;
  1146. }