acpiphp_glue.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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 <t-kochi@bq.jp.nec.com>
  30. *
  31. */
  32. /*
  33. * Lifetime rules for pci_dev:
  34. * - The one in acpiphp_func has its refcount elevated by pci_get_slot()
  35. * when the driver is loaded or when an insertion event occurs. It loses
  36. * a refcount when its ejected or the driver unloads.
  37. * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot()
  38. * when the bridge is scanned and it loses a refcount when the bridge
  39. * is removed.
  40. */
  41. #include <linux/init.h>
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/pci.h>
  45. #include <linux/smp_lock.h>
  46. #include <asm/semaphore.h>
  47. #include "../pci.h"
  48. #include "pci_hotplug.h"
  49. #include "acpiphp.h"
  50. static LIST_HEAD(bridge_list);
  51. #define MY_NAME "acpiphp_glue"
  52. static void handle_hotplug_event_bridge (acpi_handle, u32, void *);
  53. static void handle_hotplug_event_func (acpi_handle, u32, void *);
  54. /*
  55. * initialization & terminatation routines
  56. */
  57. /**
  58. * is_ejectable - determine if a slot is ejectable
  59. * @handle: handle to acpi namespace
  60. *
  61. * Ejectable slot should satisfy at least these conditions:
  62. *
  63. * 1. has _ADR method
  64. * 2. has _EJ0 method
  65. *
  66. * optionally
  67. *
  68. * 1. has _STA method
  69. * 2. has _PS0 method
  70. * 3. has _PS3 method
  71. * 4. ..
  72. *
  73. */
  74. static int is_ejectable(acpi_handle handle)
  75. {
  76. acpi_status status;
  77. acpi_handle tmp;
  78. status = acpi_get_handle(handle, "_ADR", &tmp);
  79. if (ACPI_FAILURE(status)) {
  80. return 0;
  81. }
  82. status = acpi_get_handle(handle, "_EJ0", &tmp);
  83. if (ACPI_FAILURE(status)) {
  84. return 0;
  85. }
  86. return 1;
  87. }
  88. /* callback routine to check the existence of ejectable slots */
  89. static acpi_status
  90. is_ejectable_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
  91. {
  92. int *count = (int *)context;
  93. if (is_ejectable(handle)) {
  94. (*count)++;
  95. /* only one ejectable slot is enough */
  96. return AE_CTRL_TERMINATE;
  97. } else {
  98. return AE_OK;
  99. }
  100. }
  101. /* callback routine to register each ACPI PCI slot object */
  102. static acpi_status
  103. register_slot(acpi_handle handle, u32 lvl, void *context, void **rv)
  104. {
  105. struct acpiphp_bridge *bridge = (struct acpiphp_bridge *)context;
  106. struct acpiphp_slot *slot;
  107. struct acpiphp_func *newfunc;
  108. acpi_handle tmp;
  109. acpi_status status = AE_OK;
  110. unsigned long adr, sun;
  111. int device, function;
  112. static int num_slots = 0; /* XXX if we support I/O node hotplug... */
  113. status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
  114. if (ACPI_FAILURE(status))
  115. return AE_OK;
  116. status = acpi_get_handle(handle, "_EJ0", &tmp);
  117. if (ACPI_FAILURE(status))
  118. return AE_OK;
  119. device = (adr >> 16) & 0xffff;
  120. function = adr & 0xffff;
  121. newfunc = kmalloc(sizeof(struct acpiphp_func), GFP_KERNEL);
  122. if (!newfunc)
  123. return AE_NO_MEMORY;
  124. memset(newfunc, 0, sizeof(struct acpiphp_func));
  125. INIT_LIST_HEAD(&newfunc->sibling);
  126. newfunc->handle = handle;
  127. newfunc->function = function;
  128. newfunc->flags = FUNC_HAS_EJ0;
  129. if (ACPI_SUCCESS(acpi_get_handle(handle, "_STA", &tmp)))
  130. newfunc->flags |= FUNC_HAS_STA;
  131. if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS0", &tmp)))
  132. newfunc->flags |= FUNC_HAS_PS0;
  133. if (ACPI_SUCCESS(acpi_get_handle(handle, "_PS3", &tmp)))
  134. newfunc->flags |= FUNC_HAS_PS3;
  135. status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
  136. if (ACPI_FAILURE(status))
  137. sun = -1;
  138. /* search for objects that share the same slot */
  139. for (slot = bridge->slots; slot; slot = slot->next)
  140. if (slot->device == device) {
  141. if (slot->sun != sun)
  142. warn("sibling found, but _SUN doesn't match!\n");
  143. break;
  144. }
  145. if (!slot) {
  146. slot = kmalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
  147. if (!slot) {
  148. kfree(newfunc);
  149. return AE_NO_MEMORY;
  150. }
  151. memset(slot, 0, sizeof(struct acpiphp_slot));
  152. slot->bridge = bridge;
  153. slot->id = num_slots++;
  154. slot->device = device;
  155. slot->sun = sun;
  156. INIT_LIST_HEAD(&slot->funcs);
  157. init_MUTEX(&slot->crit_sect);
  158. slot->next = bridge->slots;
  159. bridge->slots = slot;
  160. bridge->nr_slots++;
  161. dbg("found ACPI PCI Hotplug slot %d at PCI %04x:%02x:%02x\n",
  162. slot->sun, pci_domain_nr(bridge->pci_bus),
  163. bridge->pci_bus->number, slot->device);
  164. }
  165. newfunc->slot = slot;
  166. list_add_tail(&newfunc->sibling, &slot->funcs);
  167. /* associate corresponding pci_dev */
  168. newfunc->pci_dev = pci_get_slot(bridge->pci_bus,
  169. PCI_DEVFN(device, function));
  170. if (newfunc->pci_dev) {
  171. slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON);
  172. }
  173. /* install notify handler */
  174. status = acpi_install_notify_handler(handle,
  175. ACPI_SYSTEM_NOTIFY,
  176. handle_hotplug_event_func,
  177. newfunc);
  178. if (ACPI_FAILURE(status)) {
  179. err("failed to register interrupt notify handler\n");
  180. return status;
  181. }
  182. return AE_OK;
  183. }
  184. /* see if it's worth looking at this bridge */
  185. static int detect_ejectable_slots(acpi_handle *bridge_handle)
  186. {
  187. acpi_status status;
  188. int count;
  189. count = 0;
  190. /* only check slots defined directly below bridge object */
  191. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge_handle, (u32)1,
  192. is_ejectable_slot, (void *)&count, NULL);
  193. return count;
  194. }
  195. /* decode ACPI 2.0 _HPP hot plug parameters */
  196. static void decode_hpp(struct acpiphp_bridge *bridge)
  197. {
  198. acpi_status status;
  199. struct acpi_buffer buffer = { .length = ACPI_ALLOCATE_BUFFER,
  200. .pointer = NULL};
  201. union acpi_object *package;
  202. int i;
  203. /* default numbers */
  204. bridge->hpp.cache_line_size = 0x10;
  205. bridge->hpp.latency_timer = 0x40;
  206. bridge->hpp.enable_SERR = 0;
  207. bridge->hpp.enable_PERR = 0;
  208. status = acpi_evaluate_object(bridge->handle, "_HPP", NULL, &buffer);
  209. if (ACPI_FAILURE(status)) {
  210. dbg("_HPP evaluation failed\n");
  211. return;
  212. }
  213. package = (union acpi_object *) buffer.pointer;
  214. if (!package || package->type != ACPI_TYPE_PACKAGE ||
  215. package->package.count != 4 || !package->package.elements) {
  216. err("invalid _HPP object; ignoring\n");
  217. goto err_exit;
  218. }
  219. for (i = 0; i < 4; i++) {
  220. if (package->package.elements[i].type != ACPI_TYPE_INTEGER) {
  221. err("invalid _HPP parameter type; ignoring\n");
  222. goto err_exit;
  223. }
  224. }
  225. bridge->hpp.cache_line_size = package->package.elements[0].integer.value;
  226. bridge->hpp.latency_timer = package->package.elements[1].integer.value;
  227. bridge->hpp.enable_SERR = package->package.elements[2].integer.value;
  228. bridge->hpp.enable_PERR = package->package.elements[3].integer.value;
  229. dbg("_HPP parameter = (%02x, %02x, %02x, %02x)\n",
  230. bridge->hpp.cache_line_size,
  231. bridge->hpp.latency_timer,
  232. bridge->hpp.enable_SERR,
  233. bridge->hpp.enable_PERR);
  234. bridge->flags |= BRIDGE_HAS_HPP;
  235. err_exit:
  236. kfree(buffer.pointer);
  237. }
  238. /* initialize miscellaneous stuff for both root and PCI-to-PCI bridge */
  239. static void init_bridge_misc(struct acpiphp_bridge *bridge)
  240. {
  241. acpi_status status;
  242. /* decode ACPI 2.0 _HPP (hot plug parameters) */
  243. decode_hpp(bridge);
  244. /* register all slot objects under this bridge */
  245. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, (u32)1,
  246. register_slot, bridge, NULL);
  247. /* install notify handler */
  248. if (bridge->type != BRIDGE_TYPE_HOST) {
  249. status = acpi_install_notify_handler(bridge->handle,
  250. ACPI_SYSTEM_NOTIFY,
  251. handle_hotplug_event_bridge,
  252. bridge);
  253. if (ACPI_FAILURE(status)) {
  254. err("failed to register interrupt notify handler\n");
  255. }
  256. }
  257. list_add(&bridge->list, &bridge_list);
  258. }
  259. /* allocate and initialize host bridge data structure */
  260. static void add_host_bridge(acpi_handle *handle, struct pci_bus *pci_bus)
  261. {
  262. struct acpiphp_bridge *bridge;
  263. bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
  264. if (bridge == NULL)
  265. return;
  266. memset(bridge, 0, sizeof(struct acpiphp_bridge));
  267. bridge->type = BRIDGE_TYPE_HOST;
  268. bridge->handle = handle;
  269. bridge->pci_bus = pci_bus;
  270. spin_lock_init(&bridge->res_lock);
  271. init_bridge_misc(bridge);
  272. }
  273. /* allocate and initialize PCI-to-PCI bridge data structure */
  274. static void add_p2p_bridge(acpi_handle *handle, struct pci_dev *pci_dev)
  275. {
  276. struct acpiphp_bridge *bridge;
  277. bridge = kmalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
  278. if (bridge == NULL) {
  279. err("out of memory\n");
  280. return;
  281. }
  282. memset(bridge, 0, sizeof(struct acpiphp_bridge));
  283. bridge->type = BRIDGE_TYPE_P2P;
  284. bridge->handle = handle;
  285. bridge->pci_dev = pci_dev_get(pci_dev);
  286. bridge->pci_bus = pci_dev->subordinate;
  287. if (!bridge->pci_bus) {
  288. err("This is not a PCI-to-PCI bridge!\n");
  289. goto err;
  290. }
  291. spin_lock_init(&bridge->res_lock);
  292. init_bridge_misc(bridge);
  293. return;
  294. err:
  295. pci_dev_put(pci_dev);
  296. kfree(bridge);
  297. return;
  298. }
  299. /* callback routine to find P2P bridges */
  300. static acpi_status
  301. find_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
  302. {
  303. acpi_status status;
  304. acpi_handle dummy_handle;
  305. unsigned long tmp;
  306. int device, function;
  307. struct pci_dev *dev;
  308. struct pci_bus *pci_bus = context;
  309. status = acpi_get_handle(handle, "_ADR", &dummy_handle);
  310. if (ACPI_FAILURE(status))
  311. return AE_OK; /* continue */
  312. status = acpi_evaluate_integer(handle, "_ADR", NULL, &tmp);
  313. if (ACPI_FAILURE(status)) {
  314. dbg("%s: _ADR evaluation failure\n", __FUNCTION__);
  315. return AE_OK;
  316. }
  317. device = (tmp >> 16) & 0xffff;
  318. function = tmp & 0xffff;
  319. dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function));
  320. if (!dev || !dev->subordinate)
  321. goto out;
  322. /* check if this bridge has ejectable slots */
  323. if (detect_ejectable_slots(handle) > 0) {
  324. dbg("found PCI-to-PCI bridge at PCI %s\n", pci_name(dev));
  325. add_p2p_bridge(handle, dev);
  326. }
  327. out:
  328. pci_dev_put(dev);
  329. return AE_OK;
  330. }
  331. /* find hot-pluggable slots, and then find P2P bridge */
  332. static int add_bridge(acpi_handle handle)
  333. {
  334. acpi_status status;
  335. unsigned long tmp;
  336. int seg, bus;
  337. acpi_handle dummy_handle;
  338. struct pci_bus *pci_bus;
  339. /* if the bridge doesn't have _STA, we assume it is always there */
  340. status = acpi_get_handle(handle, "_STA", &dummy_handle);
  341. if (ACPI_SUCCESS(status)) {
  342. status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp);
  343. if (ACPI_FAILURE(status)) {
  344. dbg("%s: _STA evaluation failure\n", __FUNCTION__);
  345. return 0;
  346. }
  347. if ((tmp & ACPI_STA_FUNCTIONING) == 0)
  348. /* don't register this object */
  349. return 0;
  350. }
  351. /* get PCI segment number */
  352. status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp);
  353. seg = ACPI_SUCCESS(status) ? tmp : 0;
  354. /* get PCI bus number */
  355. status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp);
  356. if (ACPI_SUCCESS(status)) {
  357. bus = tmp;
  358. } else {
  359. warn("can't get bus number, assuming 0\n");
  360. bus = 0;
  361. }
  362. pci_bus = pci_find_bus(seg, bus);
  363. if (!pci_bus) {
  364. err("Can't find bus %04x:%02x\n", seg, bus);
  365. return 0;
  366. }
  367. /* check if this bridge has ejectable slots */
  368. if (detect_ejectable_slots(handle) > 0) {
  369. dbg("found PCI host-bus bridge with hot-pluggable slots\n");
  370. add_host_bridge(handle, pci_bus);
  371. return 0;
  372. }
  373. /* search P2P bridges under this host bridge */
  374. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
  375. find_p2p_bridge, pci_bus, NULL);
  376. if (ACPI_FAILURE(status))
  377. warn("find_p2p_bridge faied (error code = 0x%x)\n",status);
  378. return 0;
  379. }
  380. static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
  381. {
  382. struct list_head *head;
  383. list_for_each(head, &bridge_list) {
  384. struct acpiphp_bridge *bridge = list_entry(head,
  385. struct acpiphp_bridge, list);
  386. if (bridge->handle == handle)
  387. return bridge;
  388. }
  389. return NULL;
  390. }
  391. static void cleanup_bridge(struct acpiphp_bridge *bridge)
  392. {
  393. struct list_head *list, *tmp;
  394. struct acpiphp_slot *slot;
  395. acpi_status status;
  396. acpi_handle handle = bridge->handle;
  397. status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
  398. handle_hotplug_event_bridge);
  399. if (ACPI_FAILURE(status))
  400. err("failed to remove notify handler\n");
  401. slot = bridge->slots;
  402. while (slot) {
  403. struct acpiphp_slot *next = slot->next;
  404. list_for_each_safe (list, tmp, &slot->funcs) {
  405. struct acpiphp_func *func;
  406. func = list_entry(list, struct acpiphp_func, sibling);
  407. status = acpi_remove_notify_handler(func->handle,
  408. ACPI_SYSTEM_NOTIFY,
  409. handle_hotplug_event_func);
  410. if (ACPI_FAILURE(status))
  411. err("failed to remove notify handler\n");
  412. pci_dev_put(func->pci_dev);
  413. list_del(list);
  414. kfree(func);
  415. }
  416. kfree(slot);
  417. slot = next;
  418. }
  419. pci_dev_put(bridge->pci_dev);
  420. list_del(&bridge->list);
  421. kfree(bridge);
  422. }
  423. static acpi_status
  424. cleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv)
  425. {
  426. struct acpiphp_bridge *bridge;
  427. if (!(bridge = acpiphp_handle_to_bridge(handle)))
  428. return AE_OK;
  429. cleanup_bridge(bridge);
  430. return AE_OK;
  431. }
  432. static void remove_bridge(acpi_handle handle)
  433. {
  434. struct acpiphp_bridge *bridge;
  435. bridge = acpiphp_handle_to_bridge(handle);
  436. if (bridge) {
  437. cleanup_bridge(bridge);
  438. } else {
  439. /* clean-up p2p bridges under this host bridge */
  440. acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
  441. (u32)1, cleanup_p2p_bridge, NULL, NULL);
  442. }
  443. }
  444. static int power_on_slot(struct acpiphp_slot *slot)
  445. {
  446. acpi_status status;
  447. struct acpiphp_func *func;
  448. struct list_head *l;
  449. int retval = 0;
  450. /* if already enabled, just skip */
  451. if (slot->flags & SLOT_POWEREDON)
  452. goto err_exit;
  453. list_for_each (l, &slot->funcs) {
  454. func = list_entry(l, struct acpiphp_func, sibling);
  455. if (func->flags & FUNC_HAS_PS0) {
  456. dbg("%s: executing _PS0\n", __FUNCTION__);
  457. status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);
  458. if (ACPI_FAILURE(status)) {
  459. warn("%s: _PS0 failed\n", __FUNCTION__);
  460. retval = -1;
  461. goto err_exit;
  462. } else
  463. break;
  464. }
  465. }
  466. /* TBD: evaluate _STA to check if the slot is enabled */
  467. slot->flags |= SLOT_POWEREDON;
  468. err_exit:
  469. return retval;
  470. }
  471. static int power_off_slot(struct acpiphp_slot *slot)
  472. {
  473. acpi_status status;
  474. struct acpiphp_func *func;
  475. struct list_head *l;
  476. int retval = 0;
  477. /* if already disabled, just skip */
  478. if ((slot->flags & SLOT_POWEREDON) == 0)
  479. goto err_exit;
  480. list_for_each (l, &slot->funcs) {
  481. func = list_entry(l, struct acpiphp_func, sibling);
  482. if (func->flags & FUNC_HAS_PS3) {
  483. status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);
  484. if (ACPI_FAILURE(status)) {
  485. warn("%s: _PS3 failed\n", __FUNCTION__);
  486. retval = -1;
  487. goto err_exit;
  488. } else
  489. break;
  490. }
  491. }
  492. /* TBD: evaluate _STA to check if the slot is disabled */
  493. slot->flags &= (~SLOT_POWEREDON);
  494. err_exit:
  495. return retval;
  496. }
  497. /**
  498. * enable_device - enable, configure a slot
  499. * @slot: slot to be enabled
  500. *
  501. * This function should be called per *physical slot*,
  502. * not per each slot object in ACPI namespace.
  503. *
  504. */
  505. static int enable_device(struct acpiphp_slot *slot)
  506. {
  507. struct pci_dev *dev;
  508. struct pci_bus *bus = slot->bridge->pci_bus;
  509. struct list_head *l;
  510. struct acpiphp_func *func;
  511. int retval = 0;
  512. int num, max, pass;
  513. if (slot->flags & SLOT_ENABLED)
  514. goto err_exit;
  515. /* sanity check: dev should be NULL when hot-plugged in */
  516. dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));
  517. if (dev) {
  518. /* This case shouldn't happen */
  519. err("pci_dev structure already exists.\n");
  520. pci_dev_put(dev);
  521. retval = -1;
  522. goto err_exit;
  523. }
  524. num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
  525. if (num == 0) {
  526. err("No new device found\n");
  527. retval = -1;
  528. goto err_exit;
  529. }
  530. max = bus->secondary;
  531. for (pass = 0; pass < 2; pass++) {
  532. list_for_each_entry(dev, &bus->devices, bus_list) {
  533. if (PCI_SLOT(dev->devfn) != slot->device)
  534. continue;
  535. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  536. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  537. max = pci_scan_bridge(bus, dev, max, pass);
  538. }
  539. }
  540. pci_bus_assign_resources(bus);
  541. pci_bus_add_devices(bus);
  542. /* associate pci_dev to our representation */
  543. list_for_each (l, &slot->funcs) {
  544. func = list_entry(l, struct acpiphp_func, sibling);
  545. func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
  546. func->function));
  547. }
  548. slot->flags |= SLOT_ENABLED;
  549. err_exit:
  550. return retval;
  551. }
  552. /**
  553. * disable_device - disable a slot
  554. */
  555. static int disable_device(struct acpiphp_slot *slot)
  556. {
  557. int retval = 0;
  558. struct acpiphp_func *func;
  559. struct list_head *l;
  560. /* is this slot already disabled? */
  561. if (!(slot->flags & SLOT_ENABLED))
  562. goto err_exit;
  563. list_for_each (l, &slot->funcs) {
  564. func = list_entry(l, struct acpiphp_func, sibling);
  565. if (!func->pci_dev)
  566. continue;
  567. pci_remove_bus_device(func->pci_dev);
  568. pci_dev_put(func->pci_dev);
  569. func->pci_dev = NULL;
  570. }
  571. slot->flags &= (~SLOT_ENABLED);
  572. err_exit:
  573. return retval;
  574. }
  575. /**
  576. * get_slot_status - get ACPI slot status
  577. *
  578. * if a slot has _STA for each function and if any one of them
  579. * returned non-zero status, return it
  580. *
  581. * if a slot doesn't have _STA and if any one of its functions'
  582. * configuration space is configured, return 0x0f as a _STA
  583. *
  584. * otherwise return 0
  585. */
  586. static unsigned int get_slot_status(struct acpiphp_slot *slot)
  587. {
  588. acpi_status status;
  589. unsigned long sta = 0;
  590. u32 dvid;
  591. struct list_head *l;
  592. struct acpiphp_func *func;
  593. list_for_each (l, &slot->funcs) {
  594. func = list_entry(l, struct acpiphp_func, sibling);
  595. if (func->flags & FUNC_HAS_STA) {
  596. status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);
  597. if (ACPI_SUCCESS(status) && sta)
  598. break;
  599. } else {
  600. pci_bus_read_config_dword(slot->bridge->pci_bus,
  601. PCI_DEVFN(slot->device,
  602. func->function),
  603. PCI_VENDOR_ID, &dvid);
  604. if (dvid != 0xffffffff) {
  605. sta = ACPI_STA_ALL;
  606. break;
  607. }
  608. }
  609. }
  610. return (unsigned int)sta;
  611. }
  612. /**
  613. * acpiphp_eject_slot - physically eject the slot
  614. */
  615. static int acpiphp_eject_slot(struct acpiphp_slot *slot)
  616. {
  617. acpi_status status;
  618. struct acpiphp_func *func;
  619. struct list_head *l;
  620. struct acpi_object_list arg_list;
  621. union acpi_object arg;
  622. list_for_each (l, &slot->funcs) {
  623. func = list_entry(l, struct acpiphp_func, sibling);
  624. /* We don't want to call _EJ0 on non-existing functions. */
  625. if ((func->flags & FUNC_HAS_EJ0)) {
  626. /* _EJ0 method take one argument */
  627. arg_list.count = 1;
  628. arg_list.pointer = &arg;
  629. arg.type = ACPI_TYPE_INTEGER;
  630. arg.integer.value = 1;
  631. status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);
  632. if (ACPI_FAILURE(status)) {
  633. warn("%s: _EJ0 failed\n", __FUNCTION__);
  634. return -1;
  635. } else
  636. break;
  637. }
  638. }
  639. return 0;
  640. }
  641. /**
  642. * acpiphp_check_bridge - re-enumerate devices
  643. *
  644. * Iterate over all slots under this bridge and make sure that if a
  645. * card is present they are enabled, and if not they are disabled.
  646. */
  647. static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
  648. {
  649. struct acpiphp_slot *slot;
  650. int retval = 0;
  651. int enabled, disabled;
  652. enabled = disabled = 0;
  653. for (slot = bridge->slots; slot; slot = slot->next) {
  654. unsigned int status = get_slot_status(slot);
  655. if (slot->flags & SLOT_ENABLED) {
  656. if (status == ACPI_STA_ALL)
  657. continue;
  658. retval = acpiphp_disable_slot(slot);
  659. if (retval) {
  660. err("Error occurred in disabling\n");
  661. goto err_exit;
  662. } else {
  663. acpiphp_eject_slot(slot);
  664. }
  665. disabled++;
  666. } else {
  667. if (status != ACPI_STA_ALL)
  668. continue;
  669. retval = acpiphp_enable_slot(slot);
  670. if (retval) {
  671. err("Error occurred in enabling\n");
  672. goto err_exit;
  673. }
  674. enabled++;
  675. }
  676. }
  677. dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled);
  678. err_exit:
  679. return retval;
  680. }
  681. static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge)
  682. {
  683. u16 pci_cmd, pci_bctl;
  684. struct pci_dev *cdev;
  685. /* Program hpp values for this device */
  686. if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||
  687. (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
  688. (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))
  689. return;
  690. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  691. bridge->hpp.cache_line_size);
  692. pci_write_config_byte(dev, PCI_LATENCY_TIMER,
  693. bridge->hpp.latency_timer);
  694. pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);
  695. if (bridge->hpp.enable_SERR)
  696. pci_cmd |= PCI_COMMAND_SERR;
  697. else
  698. pci_cmd &= ~PCI_COMMAND_SERR;
  699. if (bridge->hpp.enable_PERR)
  700. pci_cmd |= PCI_COMMAND_PARITY;
  701. else
  702. pci_cmd &= ~PCI_COMMAND_PARITY;
  703. pci_write_config_word(dev, PCI_COMMAND, pci_cmd);
  704. /* Program bridge control value and child devices */
  705. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  706. pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,
  707. bridge->hpp.latency_timer);
  708. pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);
  709. if (bridge->hpp.enable_SERR)
  710. pci_bctl |= PCI_BRIDGE_CTL_SERR;
  711. else
  712. pci_bctl &= ~PCI_BRIDGE_CTL_SERR;
  713. if (bridge->hpp.enable_PERR)
  714. pci_bctl |= PCI_BRIDGE_CTL_PARITY;
  715. else
  716. pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;
  717. pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);
  718. if (dev->subordinate) {
  719. list_for_each_entry(cdev, &dev->subordinate->devices,
  720. bus_list)
  721. program_hpp(cdev, bridge);
  722. }
  723. }
  724. }
  725. static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus)
  726. {
  727. struct acpiphp_bridge bridge;
  728. struct pci_dev *dev;
  729. memset(&bridge, 0, sizeof(bridge));
  730. bridge.handle = handle;
  731. decode_hpp(&bridge);
  732. list_for_each_entry(dev, &bus->devices, bus_list)
  733. program_hpp(dev, &bridge);
  734. }
  735. /*
  736. * Remove devices for which we could not assign resources, call
  737. * arch specific code to fix-up the bus
  738. */
  739. static void acpiphp_sanitize_bus(struct pci_bus *bus)
  740. {
  741. struct pci_dev *dev;
  742. int i;
  743. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
  744. list_for_each_entry(dev, &bus->devices, bus_list) {
  745. for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
  746. struct resource *res = &dev->resource[i];
  747. if ((res->flags & type_mask) && !res->start &&
  748. res->end) {
  749. /* Could not assign a required resources
  750. * for this device, remove it */
  751. pci_remove_bus_device(dev);
  752. break;
  753. }
  754. }
  755. }
  756. }
  757. /* Program resources in newly inserted bridge */
  758. static int acpiphp_configure_bridge (acpi_handle handle)
  759. {
  760. struct acpi_pci_id pci_id;
  761. struct pci_bus *bus;
  762. if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {
  763. err("cannot get PCI domain and bus number for bridge\n");
  764. return -EINVAL;
  765. }
  766. bus = pci_find_bus(pci_id.segment, pci_id.bus);
  767. if (!bus) {
  768. err("cannot find bus %d:%d\n",
  769. pci_id.segment, pci_id.bus);
  770. return -EINVAL;
  771. }
  772. pci_bus_size_bridges(bus);
  773. pci_bus_assign_resources(bus);
  774. acpiphp_sanitize_bus(bus);
  775. acpiphp_set_hpp_values(handle, bus);
  776. pci_enable_bridges(bus);
  777. return 0;
  778. }
  779. static void handle_bridge_insertion(acpi_handle handle, u32 type)
  780. {
  781. struct acpi_device *device, *pdevice;
  782. acpi_handle phandle;
  783. if ((type != ACPI_NOTIFY_BUS_CHECK) &&
  784. (type != ACPI_NOTIFY_DEVICE_CHECK)) {
  785. err("unexpected notification type %d\n", type);
  786. return;
  787. }
  788. acpi_get_parent(handle, &phandle);
  789. if (acpi_bus_get_device(phandle, &pdevice)) {
  790. dbg("no parent device, assuming NULL\n");
  791. pdevice = NULL;
  792. }
  793. if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {
  794. err("cannot add bridge to acpi list\n");
  795. return;
  796. }
  797. if (!acpiphp_configure_bridge(handle) &&
  798. !acpi_bus_start(device))
  799. add_bridge(handle);
  800. else
  801. err("cannot configure and start bridge\n");
  802. }
  803. /*
  804. * ACPI event handlers
  805. */
  806. /**
  807. * handle_hotplug_event_bridge - handle ACPI event on bridges
  808. *
  809. * @handle: Notify()'ed acpi_handle
  810. * @type: Notify code
  811. * @context: pointer to acpiphp_bridge structure
  812. *
  813. * handles ACPI event notification on {host,p2p} bridges
  814. *
  815. */
  816. static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context)
  817. {
  818. struct acpiphp_bridge *bridge;
  819. char objname[64];
  820. struct acpi_buffer buffer = { .length = sizeof(objname),
  821. .pointer = objname };
  822. struct acpi_device *device;
  823. if (acpi_bus_get_device(handle, &device)) {
  824. /* This bridge must have just been physically inserted */
  825. handle_bridge_insertion(handle, type);
  826. return;
  827. }
  828. bridge = acpiphp_handle_to_bridge(handle);
  829. if (!bridge) {
  830. err("cannot get bridge info\n");
  831. return;
  832. }
  833. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  834. switch (type) {
  835. case ACPI_NOTIFY_BUS_CHECK:
  836. /* bus re-enumerate */
  837. dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
  838. acpiphp_check_bridge(bridge);
  839. break;
  840. case ACPI_NOTIFY_DEVICE_CHECK:
  841. /* device check */
  842. dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
  843. acpiphp_check_bridge(bridge);
  844. break;
  845. case ACPI_NOTIFY_DEVICE_WAKE:
  846. /* wake event */
  847. dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
  848. break;
  849. case ACPI_NOTIFY_EJECT_REQUEST:
  850. /* request device eject */
  851. dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
  852. break;
  853. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  854. printk(KERN_ERR "Device %s cannot be configured due"
  855. " to a frequency mismatch\n", objname);
  856. break;
  857. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  858. printk(KERN_ERR "Device %s cannot be configured due"
  859. " to a bus mode mismatch\n", objname);
  860. break;
  861. case ACPI_NOTIFY_POWER_FAULT:
  862. printk(KERN_ERR "Device %s has suffered a power fault\n",
  863. objname);
  864. break;
  865. default:
  866. warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
  867. break;
  868. }
  869. }
  870. /**
  871. * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots)
  872. *
  873. * @handle: Notify()'ed acpi_handle
  874. * @type: Notify code
  875. * @context: pointer to acpiphp_func structure
  876. *
  877. * handles ACPI event notification on slots
  878. *
  879. */
  880. static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context)
  881. {
  882. struct acpiphp_func *func;
  883. char objname[64];
  884. struct acpi_buffer buffer = { .length = sizeof(objname),
  885. .pointer = objname };
  886. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  887. func = (struct acpiphp_func *)context;
  888. switch (type) {
  889. case ACPI_NOTIFY_BUS_CHECK:
  890. /* bus re-enumerate */
  891. dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);
  892. acpiphp_enable_slot(func->slot);
  893. break;
  894. case ACPI_NOTIFY_DEVICE_CHECK:
  895. /* device check : re-enumerate from parent bus */
  896. dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);
  897. acpiphp_check_bridge(func->slot->bridge);
  898. break;
  899. case ACPI_NOTIFY_DEVICE_WAKE:
  900. /* wake event */
  901. dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);
  902. break;
  903. case ACPI_NOTIFY_EJECT_REQUEST:
  904. /* request device eject */
  905. dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);
  906. if (!(acpiphp_disable_slot(func->slot)))
  907. acpiphp_eject_slot(func->slot);
  908. break;
  909. default:
  910. warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);
  911. break;
  912. }
  913. }
  914. static int is_root_bridge(acpi_handle handle)
  915. {
  916. acpi_status status;
  917. struct acpi_device_info *info;
  918. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  919. int i;
  920. status = acpi_get_object_info(handle, &buffer);
  921. if (ACPI_SUCCESS(status)) {
  922. info = buffer.pointer;
  923. if ((info->valid & ACPI_VALID_HID) &&
  924. !strcmp(PCI_ROOT_HID_STRING,
  925. info->hardware_id.value)) {
  926. acpi_os_free(buffer.pointer);
  927. return 1;
  928. }
  929. if (info->valid & ACPI_VALID_CID) {
  930. for (i=0; i < info->compatibility_id.count; i++) {
  931. if (!strcmp(PCI_ROOT_HID_STRING,
  932. info->compatibility_id.id[i].value)) {
  933. acpi_os_free(buffer.pointer);
  934. return 1;
  935. }
  936. }
  937. }
  938. }
  939. return 0;
  940. }
  941. static acpi_status
  942. find_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
  943. {
  944. int *count = (int *)context;
  945. if (is_root_bridge(handle)) {
  946. acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
  947. handle_hotplug_event_bridge, NULL);
  948. (*count)++;
  949. }
  950. return AE_OK ;
  951. }
  952. static struct acpi_pci_driver acpi_pci_hp_driver = {
  953. .add = add_bridge,
  954. .remove = remove_bridge,
  955. };
  956. /**
  957. * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures
  958. *
  959. */
  960. int __init acpiphp_glue_init(void)
  961. {
  962. int num = 0;
  963. acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
  964. ACPI_UINT32_MAX, find_root_bridges, &num, NULL);
  965. if (num <= 0)
  966. return -1;
  967. else
  968. acpi_pci_register_driver(&acpi_pci_hp_driver);
  969. return 0;
  970. }
  971. /**
  972. * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures
  973. *
  974. * This function frees all data allocated in acpiphp_glue_init()
  975. */
  976. void __exit acpiphp_glue_exit(void)
  977. {
  978. acpi_pci_unregister_driver(&acpi_pci_hp_driver);
  979. }
  980. /**
  981. * acpiphp_get_num_slots - count number of slots in a system
  982. */
  983. int __init acpiphp_get_num_slots(void)
  984. {
  985. struct list_head *node;
  986. struct acpiphp_bridge *bridge;
  987. int num_slots;
  988. num_slots = 0;
  989. list_for_each (node, &bridge_list) {
  990. bridge = (struct acpiphp_bridge *)node;
  991. dbg("Bus %04x:%02x has %d slot%s\n",
  992. pci_domain_nr(bridge->pci_bus),
  993. bridge->pci_bus->number, bridge->nr_slots,
  994. bridge->nr_slots == 1 ? "" : "s");
  995. num_slots += bridge->nr_slots;
  996. }
  997. dbg("Total %d slots\n", num_slots);
  998. return num_slots;
  999. }
  1000. #if 0
  1001. /**
  1002. * acpiphp_for_each_slot - call function for each slot
  1003. * @fn: callback function
  1004. * @data: context to be passed to callback function
  1005. *
  1006. */
  1007. static int acpiphp_for_each_slot(acpiphp_callback fn, void *data)
  1008. {
  1009. struct list_head *node;
  1010. struct acpiphp_bridge *bridge;
  1011. struct acpiphp_slot *slot;
  1012. int retval = 0;
  1013. list_for_each (node, &bridge_list) {
  1014. bridge = (struct acpiphp_bridge *)node;
  1015. for (slot = bridge->slots; slot; slot = slot->next) {
  1016. retval = fn(slot, data);
  1017. if (!retval)
  1018. goto err_exit;
  1019. }
  1020. }
  1021. err_exit:
  1022. return retval;
  1023. }
  1024. #endif
  1025. /* search matching slot from id */
  1026. struct acpiphp_slot *get_slot_from_id(int id)
  1027. {
  1028. struct list_head *node;
  1029. struct acpiphp_bridge *bridge;
  1030. struct acpiphp_slot *slot;
  1031. list_for_each (node, &bridge_list) {
  1032. bridge = (struct acpiphp_bridge *)node;
  1033. for (slot = bridge->slots; slot; slot = slot->next)
  1034. if (slot->id == id)
  1035. return slot;
  1036. }
  1037. /* should never happen! */
  1038. err("%s: no object for id %d\n", __FUNCTION__, id);
  1039. WARN_ON(1);
  1040. return NULL;
  1041. }
  1042. /**
  1043. * acpiphp_enable_slot - power on slot
  1044. */
  1045. int acpiphp_enable_slot(struct acpiphp_slot *slot)
  1046. {
  1047. int retval;
  1048. down(&slot->crit_sect);
  1049. /* wake up all functions */
  1050. retval = power_on_slot(slot);
  1051. if (retval)
  1052. goto err_exit;
  1053. if (get_slot_status(slot) == ACPI_STA_ALL)
  1054. /* configure all functions */
  1055. retval = enable_device(slot);
  1056. err_exit:
  1057. up(&slot->crit_sect);
  1058. return retval;
  1059. }
  1060. /**
  1061. * acpiphp_disable_slot - power off slot
  1062. */
  1063. int acpiphp_disable_slot(struct acpiphp_slot *slot)
  1064. {
  1065. int retval = 0;
  1066. down(&slot->crit_sect);
  1067. /* unconfigure all functions */
  1068. retval = disable_device(slot);
  1069. if (retval)
  1070. goto err_exit;
  1071. /* power off all functions */
  1072. retval = power_off_slot(slot);
  1073. if (retval)
  1074. goto err_exit;
  1075. err_exit:
  1076. up(&slot->crit_sect);
  1077. return retval;
  1078. }
  1079. /*
  1080. * slot enabled: 1
  1081. * slot disabled: 0
  1082. */
  1083. u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
  1084. {
  1085. return (slot->flags & SLOT_POWEREDON);
  1086. }
  1087. /*
  1088. * latch closed: 1
  1089. * latch open: 0
  1090. */
  1091. u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
  1092. {
  1093. unsigned int sta;
  1094. sta = get_slot_status(slot);
  1095. return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0;
  1096. }
  1097. /*
  1098. * adapter presence : 1
  1099. * absence : 0
  1100. */
  1101. u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
  1102. {
  1103. unsigned int sta;
  1104. sta = get_slot_status(slot);
  1105. return (sta == 0) ? 0 : 1;
  1106. }
  1107. /*
  1108. * pci address (seg/bus/dev)
  1109. */
  1110. u32 acpiphp_get_address(struct acpiphp_slot *slot)
  1111. {
  1112. u32 address;
  1113. struct pci_bus *pci_bus = slot->bridge->pci_bus;
  1114. address = (pci_domain_nr(pci_bus) << 16) |
  1115. (pci_bus->number << 8) |
  1116. slot->device;
  1117. return address;
  1118. }