acpiphp_glue.c 32 KB

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