scan.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. /*
  2. * scan.c - support for transforming the ACPI namespace into individual objects
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/acpi.h>
  7. #include <acpi/acpi_drivers.h>
  8. #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */
  9. #define _COMPONENT ACPI_BUS_COMPONENT
  10. ACPI_MODULE_NAME("scan")
  11. #define STRUCT_TO_INT(s) (*((int*)&s))
  12. extern struct acpi_device *acpi_root;
  13. #define ACPI_BUS_CLASS "system_bus"
  14. #define ACPI_BUS_HID "ACPI_BUS"
  15. #define ACPI_BUS_DRIVER_NAME "ACPI Bus Driver"
  16. #define ACPI_BUS_DEVICE_NAME "System Bus"
  17. static LIST_HEAD(acpi_device_list);
  18. DEFINE_SPINLOCK(acpi_device_lock);
  19. LIST_HEAD(acpi_wakeup_device_list);
  20. static int acpi_bus_trim(struct acpi_device *start, int rmdevice);
  21. static void acpi_device_release(struct kobject *kobj)
  22. {
  23. struct acpi_device *dev = container_of(kobj, struct acpi_device, kobj);
  24. kfree(dev->pnp.cid_list);
  25. kfree(dev);
  26. }
  27. struct acpi_device_attribute {
  28. struct attribute attr;
  29. ssize_t(*show) (struct acpi_device *, char *);
  30. ssize_t(*store) (struct acpi_device *, const char *, size_t);
  31. };
  32. typedef void acpi_device_sysfs_files(struct kobject *,
  33. const struct attribute *);
  34. static void setup_sys_fs_device_files(struct acpi_device *dev,
  35. acpi_device_sysfs_files * func);
  36. #define create_sysfs_device_files(dev) \
  37. setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_create_file)
  38. #define remove_sysfs_device_files(dev) \
  39. setup_sys_fs_device_files(dev, (acpi_device_sysfs_files *)&sysfs_remove_file)
  40. #define to_acpi_device(n) container_of(n, struct acpi_device, kobj)
  41. #define to_handle_attr(n) container_of(n, struct acpi_device_attribute, attr);
  42. static ssize_t acpi_device_attr_show(struct kobject *kobj,
  43. struct attribute *attr, char *buf)
  44. {
  45. struct acpi_device *device = to_acpi_device(kobj);
  46. struct acpi_device_attribute *attribute = to_handle_attr(attr);
  47. return attribute->show ? attribute->show(device, buf) : -EIO;
  48. }
  49. static ssize_t acpi_device_attr_store(struct kobject *kobj,
  50. struct attribute *attr, const char *buf,
  51. size_t len)
  52. {
  53. struct acpi_device *device = to_acpi_device(kobj);
  54. struct acpi_device_attribute *attribute = to_handle_attr(attr);
  55. return attribute->store ? attribute->store(device, buf, len) : -EIO;
  56. }
  57. static struct sysfs_ops acpi_device_sysfs_ops = {
  58. .show = acpi_device_attr_show,
  59. .store = acpi_device_attr_store,
  60. };
  61. static struct kobj_type ktype_acpi_ns = {
  62. .sysfs_ops = &acpi_device_sysfs_ops,
  63. .release = acpi_device_release,
  64. };
  65. static int namespace_uevent(struct kset *kset, struct kobject *kobj,
  66. char **envp, int num_envp, char *buffer,
  67. int buffer_size)
  68. {
  69. struct acpi_device *dev = to_acpi_device(kobj);
  70. int i = 0;
  71. int len = 0;
  72. if (!dev->driver)
  73. return 0;
  74. if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
  75. "PHYSDEVDRIVER=%s", dev->driver->name))
  76. return -ENOMEM;
  77. envp[i] = NULL;
  78. return 0;
  79. }
  80. static struct kset_uevent_ops namespace_uevent_ops = {
  81. .uevent = &namespace_uevent,
  82. };
  83. static struct kset acpi_namespace_kset = {
  84. .kobj = {
  85. .name = "namespace",
  86. },
  87. .subsys = &acpi_subsys,
  88. .ktype = &ktype_acpi_ns,
  89. .uevent_ops = &namespace_uevent_ops,
  90. };
  91. static void acpi_device_register(struct acpi_device *device,
  92. struct acpi_device *parent)
  93. {
  94. /*
  95. * Linkage
  96. * -------
  97. * Link this device to its parent and siblings.
  98. */
  99. INIT_LIST_HEAD(&device->children);
  100. INIT_LIST_HEAD(&device->node);
  101. INIT_LIST_HEAD(&device->g_list);
  102. INIT_LIST_HEAD(&device->wakeup_list);
  103. spin_lock(&acpi_device_lock);
  104. if (device->parent) {
  105. list_add_tail(&device->node, &device->parent->children);
  106. list_add_tail(&device->g_list, &device->parent->g_list);
  107. } else
  108. list_add_tail(&device->g_list, &acpi_device_list);
  109. if (device->wakeup.flags.valid)
  110. list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
  111. spin_unlock(&acpi_device_lock);
  112. strlcpy(device->kobj.name, device->pnp.bus_id, KOBJ_NAME_LEN);
  113. if (parent)
  114. device->kobj.parent = &parent->kobj;
  115. device->kobj.ktype = &ktype_acpi_ns;
  116. device->kobj.kset = &acpi_namespace_kset;
  117. kobject_register(&device->kobj);
  118. create_sysfs_device_files(device);
  119. }
  120. static int acpi_device_unregister(struct acpi_device *device, int type)
  121. {
  122. spin_lock(&acpi_device_lock);
  123. if (device->parent) {
  124. list_del(&device->node);
  125. list_del(&device->g_list);
  126. } else
  127. list_del(&device->g_list);
  128. list_del(&device->wakeup_list);
  129. spin_unlock(&acpi_device_lock);
  130. acpi_detach_data(device->handle, acpi_bus_data_handler);
  131. remove_sysfs_device_files(device);
  132. kobject_unregister(&device->kobj);
  133. return 0;
  134. }
  135. void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
  136. {
  137. ACPI_FUNCTION_TRACE("acpi_bus_data_handler");
  138. /* TBD */
  139. return_VOID;
  140. }
  141. static int acpi_bus_get_power_flags(struct acpi_device *device)
  142. {
  143. acpi_status status = 0;
  144. acpi_handle handle = NULL;
  145. u32 i = 0;
  146. ACPI_FUNCTION_TRACE("acpi_bus_get_power_flags");
  147. /*
  148. * Power Management Flags
  149. */
  150. status = acpi_get_handle(device->handle, "_PSC", &handle);
  151. if (ACPI_SUCCESS(status))
  152. device->power.flags.explicit_get = 1;
  153. status = acpi_get_handle(device->handle, "_IRC", &handle);
  154. if (ACPI_SUCCESS(status))
  155. device->power.flags.inrush_current = 1;
  156. /*
  157. * Enumerate supported power management states
  158. */
  159. for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
  160. struct acpi_device_power_state *ps = &device->power.states[i];
  161. char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
  162. /* Evaluate "_PRx" to se if power resources are referenced */
  163. acpi_evaluate_reference(device->handle, object_name, NULL,
  164. &ps->resources);
  165. if (ps->resources.count) {
  166. device->power.flags.power_resources = 1;
  167. ps->flags.valid = 1;
  168. }
  169. /* Evaluate "_PSx" to see if we can do explicit sets */
  170. object_name[2] = 'S';
  171. status = acpi_get_handle(device->handle, object_name, &handle);
  172. if (ACPI_SUCCESS(status)) {
  173. ps->flags.explicit_set = 1;
  174. ps->flags.valid = 1;
  175. }
  176. /* State is valid if we have some power control */
  177. if (ps->resources.count || ps->flags.explicit_set)
  178. ps->flags.valid = 1;
  179. ps->power = -1; /* Unknown - driver assigned */
  180. ps->latency = -1; /* Unknown - driver assigned */
  181. }
  182. /* Set defaults for D0 and D3 states (always valid) */
  183. device->power.states[ACPI_STATE_D0].flags.valid = 1;
  184. device->power.states[ACPI_STATE_D0].power = 100;
  185. device->power.states[ACPI_STATE_D3].flags.valid = 1;
  186. device->power.states[ACPI_STATE_D3].power = 0;
  187. /* TBD: System wake support and resource requirements. */
  188. device->power.state = ACPI_STATE_UNKNOWN;
  189. return_VALUE(0);
  190. }
  191. int acpi_match_ids(struct acpi_device *device, char *ids)
  192. {
  193. int error = 0;
  194. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  195. if (device->flags.hardware_id)
  196. if (strstr(ids, device->pnp.hardware_id))
  197. goto Done;
  198. if (device->flags.compatible_ids) {
  199. struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
  200. int i;
  201. /* compare multiple _CID entries against driver ids */
  202. for (i = 0; i < cid_list->count; i++) {
  203. if (strstr(ids, cid_list->id[i].value))
  204. goto Done;
  205. }
  206. }
  207. error = -ENOENT;
  208. Done:
  209. if (buffer.pointer)
  210. acpi_os_free(buffer.pointer);
  211. return error;
  212. }
  213. static acpi_status
  214. acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
  215. union acpi_object *package)
  216. {
  217. int i = 0;
  218. union acpi_object *element = NULL;
  219. if (!device || !package || (package->package.count < 2))
  220. return AE_BAD_PARAMETER;
  221. element = &(package->package.elements[0]);
  222. if (!element)
  223. return AE_BAD_PARAMETER;
  224. if (element->type == ACPI_TYPE_PACKAGE) {
  225. if ((element->package.count < 2) ||
  226. (element->package.elements[0].type !=
  227. ACPI_TYPE_LOCAL_REFERENCE)
  228. || (element->package.elements[1].type != ACPI_TYPE_INTEGER))
  229. return AE_BAD_DATA;
  230. device->wakeup.gpe_device =
  231. element->package.elements[0].reference.handle;
  232. device->wakeup.gpe_number =
  233. (u32) element->package.elements[1].integer.value;
  234. } else if (element->type == ACPI_TYPE_INTEGER) {
  235. device->wakeup.gpe_number = element->integer.value;
  236. } else
  237. return AE_BAD_DATA;
  238. element = &(package->package.elements[1]);
  239. if (element->type != ACPI_TYPE_INTEGER) {
  240. return AE_BAD_DATA;
  241. }
  242. device->wakeup.sleep_state = element->integer.value;
  243. if ((package->package.count - 2) > ACPI_MAX_HANDLES) {
  244. return AE_NO_MEMORY;
  245. }
  246. device->wakeup.resources.count = package->package.count - 2;
  247. for (i = 0; i < device->wakeup.resources.count; i++) {
  248. element = &(package->package.elements[i + 2]);
  249. if (element->type != ACPI_TYPE_ANY) {
  250. return AE_BAD_DATA;
  251. }
  252. device->wakeup.resources.handles[i] = element->reference.handle;
  253. }
  254. return AE_OK;
  255. }
  256. static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
  257. {
  258. acpi_status status = 0;
  259. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  260. union acpi_object *package = NULL;
  261. ACPI_FUNCTION_TRACE("acpi_bus_get_wakeup_flags");
  262. /* _PRW */
  263. status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
  264. if (ACPI_FAILURE(status)) {
  265. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRW\n"));
  266. goto end;
  267. }
  268. package = (union acpi_object *)buffer.pointer;
  269. status = acpi_bus_extract_wakeup_device_power_package(device, package);
  270. if (ACPI_FAILURE(status)) {
  271. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  272. "Error extracting _PRW package\n"));
  273. goto end;
  274. }
  275. acpi_os_free(buffer.pointer);
  276. device->wakeup.flags.valid = 1;
  277. /* Power button, Lid switch always enable wakeup */
  278. if (!acpi_match_ids(device, "PNP0C0D,PNP0C0C,PNP0C0E"))
  279. device->wakeup.flags.run_wake = 1;
  280. end:
  281. if (ACPI_FAILURE(status))
  282. device->flags.wake_capable = 0;
  283. return_VALUE(0);
  284. }
  285. /* --------------------------------------------------------------------------
  286. ACPI sysfs device file support
  287. -------------------------------------------------------------------------- */
  288. static ssize_t acpi_eject_store(struct acpi_device *device,
  289. const char *buf, size_t count);
  290. #define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \
  291. static struct acpi_device_attribute acpi_device_attr_##_name = \
  292. __ATTR(_name, _mode, _show, _store)
  293. ACPI_DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store);
  294. /**
  295. * setup_sys_fs_device_files - sets up the device files under device namespace
  296. * @dev: acpi_device object
  297. * @func: function pointer to create or destroy the device file
  298. */
  299. static void
  300. setup_sys_fs_device_files(struct acpi_device *dev,
  301. acpi_device_sysfs_files * func)
  302. {
  303. acpi_status status;
  304. acpi_handle temp = NULL;
  305. /*
  306. * If device has _EJ0, 'eject' file is created that is used to trigger
  307. * hot-removal function from userland.
  308. */
  309. status = acpi_get_handle(dev->handle, "_EJ0", &temp);
  310. if (ACPI_SUCCESS(status))
  311. (*(func)) (&dev->kobj, &acpi_device_attr_eject.attr);
  312. }
  313. static int acpi_eject_operation(acpi_handle handle, int lockable)
  314. {
  315. struct acpi_object_list arg_list;
  316. union acpi_object arg;
  317. acpi_status status = AE_OK;
  318. /*
  319. * TBD: evaluate _PS3?
  320. */
  321. if (lockable) {
  322. arg_list.count = 1;
  323. arg_list.pointer = &arg;
  324. arg.type = ACPI_TYPE_INTEGER;
  325. arg.integer.value = 0;
  326. acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
  327. }
  328. arg_list.count = 1;
  329. arg_list.pointer = &arg;
  330. arg.type = ACPI_TYPE_INTEGER;
  331. arg.integer.value = 1;
  332. /*
  333. * TBD: _EJD support.
  334. */
  335. status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
  336. if (ACPI_FAILURE(status)) {
  337. return (-ENODEV);
  338. }
  339. return (0);
  340. }
  341. static ssize_t
  342. acpi_eject_store(struct acpi_device *device, const char *buf, size_t count)
  343. {
  344. int result;
  345. int ret = count;
  346. int islockable;
  347. acpi_status status;
  348. acpi_handle handle;
  349. acpi_object_type type = 0;
  350. if ((!count) || (buf[0] != '1')) {
  351. return -EINVAL;
  352. }
  353. #ifndef FORCE_EJECT
  354. if (device->driver == NULL) {
  355. ret = -ENODEV;
  356. goto err;
  357. }
  358. #endif
  359. status = acpi_get_type(device->handle, &type);
  360. if (ACPI_FAILURE(status) || (!device->flags.ejectable)) {
  361. ret = -ENODEV;
  362. goto err;
  363. }
  364. islockable = device->flags.lockable;
  365. handle = device->handle;
  366. if (type == ACPI_TYPE_PROCESSOR)
  367. result = acpi_bus_trim(device, 0);
  368. else
  369. result = acpi_bus_trim(device, 1);
  370. if (!result)
  371. result = acpi_eject_operation(handle, islockable);
  372. if (result) {
  373. ret = -EBUSY;
  374. }
  375. err:
  376. return ret;
  377. }
  378. /* --------------------------------------------------------------------------
  379. Performance Management
  380. -------------------------------------------------------------------------- */
  381. static int acpi_bus_get_perf_flags(struct acpi_device *device)
  382. {
  383. device->performance.state = ACPI_STATE_UNKNOWN;
  384. return 0;
  385. }
  386. /* --------------------------------------------------------------------------
  387. Driver Management
  388. -------------------------------------------------------------------------- */
  389. static LIST_HEAD(acpi_bus_drivers);
  390. static DECLARE_MUTEX(acpi_bus_drivers_lock);
  391. /**
  392. * acpi_bus_match - match device IDs to driver's supported IDs
  393. * @device: the device that we are trying to match to a driver
  394. * @driver: driver whose device id table is being checked
  395. *
  396. * Checks the device's hardware (_HID) or compatible (_CID) ids to see if it
  397. * matches the specified driver's criteria.
  398. */
  399. static int
  400. acpi_bus_match(struct acpi_device *device, struct acpi_driver *driver)
  401. {
  402. if (driver && driver->ops.match)
  403. return driver->ops.match(device, driver);
  404. return acpi_match_ids(device, driver->ids);
  405. }
  406. /**
  407. * acpi_bus_driver_init - add a device to a driver
  408. * @device: the device to add and initialize
  409. * @driver: driver for the device
  410. *
  411. * Used to initialize a device via its device driver. Called whenever a
  412. * driver is bound to a device. Invokes the driver's add() and start() ops.
  413. */
  414. static int
  415. acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
  416. {
  417. int result = 0;
  418. ACPI_FUNCTION_TRACE("acpi_bus_driver_init");
  419. if (!device || !driver)
  420. return_VALUE(-EINVAL);
  421. if (!driver->ops.add)
  422. return_VALUE(-ENOSYS);
  423. result = driver->ops.add(device);
  424. if (result) {
  425. device->driver = NULL;
  426. acpi_driver_data(device) = NULL;
  427. return_VALUE(result);
  428. }
  429. device->driver = driver;
  430. /*
  431. * TBD - Configuration Management: Assign resources to device based
  432. * upon possible configuration and currently allocated resources.
  433. */
  434. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  435. "Driver successfully bound to device\n"));
  436. return_VALUE(0);
  437. }
  438. static int acpi_start_single_object(struct acpi_device *device)
  439. {
  440. int result = 0;
  441. struct acpi_driver *driver;
  442. ACPI_FUNCTION_TRACE("acpi_start_single_object");
  443. if (!(driver = device->driver))
  444. return_VALUE(0);
  445. if (driver->ops.start) {
  446. result = driver->ops.start(device);
  447. if (result && driver->ops.remove)
  448. driver->ops.remove(device, ACPI_BUS_REMOVAL_NORMAL);
  449. }
  450. return_VALUE(result);
  451. }
  452. static int acpi_driver_attach(struct acpi_driver *drv)
  453. {
  454. struct list_head *node, *next;
  455. int count = 0;
  456. ACPI_FUNCTION_TRACE("acpi_driver_attach");
  457. spin_lock(&acpi_device_lock);
  458. list_for_each_safe(node, next, &acpi_device_list) {
  459. struct acpi_device *dev =
  460. container_of(node, struct acpi_device, g_list);
  461. if (dev->driver || !dev->status.present)
  462. continue;
  463. spin_unlock(&acpi_device_lock);
  464. if (!acpi_bus_match(dev, drv)) {
  465. if (!acpi_bus_driver_init(dev, drv)) {
  466. acpi_start_single_object(dev);
  467. atomic_inc(&drv->references);
  468. count++;
  469. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  470. "Found driver [%s] for device [%s]\n",
  471. drv->name, dev->pnp.bus_id));
  472. }
  473. }
  474. spin_lock(&acpi_device_lock);
  475. }
  476. spin_unlock(&acpi_device_lock);
  477. return_VALUE(count);
  478. }
  479. static int acpi_driver_detach(struct acpi_driver *drv)
  480. {
  481. struct list_head *node, *next;
  482. ACPI_FUNCTION_TRACE("acpi_driver_detach");
  483. spin_lock(&acpi_device_lock);
  484. list_for_each_safe(node, next, &acpi_device_list) {
  485. struct acpi_device *dev =
  486. container_of(node, struct acpi_device, g_list);
  487. if (dev->driver == drv) {
  488. spin_unlock(&acpi_device_lock);
  489. if (drv->ops.remove)
  490. drv->ops.remove(dev, ACPI_BUS_REMOVAL_NORMAL);
  491. spin_lock(&acpi_device_lock);
  492. dev->driver = NULL;
  493. dev->driver_data = NULL;
  494. atomic_dec(&drv->references);
  495. }
  496. }
  497. spin_unlock(&acpi_device_lock);
  498. return_VALUE(0);
  499. }
  500. /**
  501. * acpi_bus_register_driver - register a driver with the ACPI bus
  502. * @driver: driver being registered
  503. *
  504. * Registers a driver with the ACPI bus. Searches the namespace for all
  505. * devices that match the driver's criteria and binds. Returns the
  506. * number of devices that were claimed by the driver, or a negative
  507. * error status for failure.
  508. */
  509. int acpi_bus_register_driver(struct acpi_driver *driver)
  510. {
  511. int count;
  512. ACPI_FUNCTION_TRACE("acpi_bus_register_driver");
  513. if (acpi_disabled)
  514. return_VALUE(-ENODEV);
  515. if (!driver)
  516. return_VALUE(-EINVAL);
  517. spin_lock(&acpi_device_lock);
  518. list_add_tail(&driver->node, &acpi_bus_drivers);
  519. spin_unlock(&acpi_device_lock);
  520. count = acpi_driver_attach(driver);
  521. return_VALUE(count);
  522. }
  523. EXPORT_SYMBOL(acpi_bus_register_driver);
  524. /**
  525. * acpi_bus_unregister_driver - unregisters a driver with the APIC bus
  526. * @driver: driver to unregister
  527. *
  528. * Unregisters a driver with the ACPI bus. Searches the namespace for all
  529. * devices that match the driver's criteria and unbinds.
  530. */
  531. int acpi_bus_unregister_driver(struct acpi_driver *driver)
  532. {
  533. int error = 0;
  534. ACPI_FUNCTION_TRACE("acpi_bus_unregister_driver");
  535. if (driver) {
  536. acpi_driver_detach(driver);
  537. if (!atomic_read(&driver->references)) {
  538. spin_lock(&acpi_device_lock);
  539. list_del_init(&driver->node);
  540. spin_unlock(&acpi_device_lock);
  541. }
  542. } else
  543. error = -EINVAL;
  544. return_VALUE(error);
  545. }
  546. EXPORT_SYMBOL(acpi_bus_unregister_driver);
  547. /**
  548. * acpi_bus_find_driver - check if there is a driver installed for the device
  549. * @device: device that we are trying to find a supporting driver for
  550. *
  551. * Parses the list of registered drivers looking for a driver applicable for
  552. * the specified device.
  553. */
  554. static int acpi_bus_find_driver(struct acpi_device *device)
  555. {
  556. int result = 0;
  557. struct list_head *node, *next;
  558. ACPI_FUNCTION_TRACE("acpi_bus_find_driver");
  559. spin_lock(&acpi_device_lock);
  560. list_for_each_safe(node, next, &acpi_bus_drivers) {
  561. struct acpi_driver *driver =
  562. container_of(node, struct acpi_driver, node);
  563. atomic_inc(&driver->references);
  564. spin_unlock(&acpi_device_lock);
  565. if (!acpi_bus_match(device, driver)) {
  566. result = acpi_bus_driver_init(device, driver);
  567. if (!result)
  568. goto Done;
  569. }
  570. atomic_dec(&driver->references);
  571. spin_lock(&acpi_device_lock);
  572. }
  573. spin_unlock(&acpi_device_lock);
  574. Done:
  575. return_VALUE(result);
  576. }
  577. /* --------------------------------------------------------------------------
  578. Device Enumeration
  579. -------------------------------------------------------------------------- */
  580. static int acpi_bus_get_flags(struct acpi_device *device)
  581. {
  582. acpi_status status = AE_OK;
  583. acpi_handle temp = NULL;
  584. ACPI_FUNCTION_TRACE("acpi_bus_get_flags");
  585. /* Presence of _STA indicates 'dynamic_status' */
  586. status = acpi_get_handle(device->handle, "_STA", &temp);
  587. if (ACPI_SUCCESS(status))
  588. device->flags.dynamic_status = 1;
  589. /* Presence of _CID indicates 'compatible_ids' */
  590. status = acpi_get_handle(device->handle, "_CID", &temp);
  591. if (ACPI_SUCCESS(status))
  592. device->flags.compatible_ids = 1;
  593. /* Presence of _RMV indicates 'removable' */
  594. status = acpi_get_handle(device->handle, "_RMV", &temp);
  595. if (ACPI_SUCCESS(status))
  596. device->flags.removable = 1;
  597. /* Presence of _EJD|_EJ0 indicates 'ejectable' */
  598. status = acpi_get_handle(device->handle, "_EJD", &temp);
  599. if (ACPI_SUCCESS(status))
  600. device->flags.ejectable = 1;
  601. else {
  602. status = acpi_get_handle(device->handle, "_EJ0", &temp);
  603. if (ACPI_SUCCESS(status))
  604. device->flags.ejectable = 1;
  605. }
  606. /* Presence of _LCK indicates 'lockable' */
  607. status = acpi_get_handle(device->handle, "_LCK", &temp);
  608. if (ACPI_SUCCESS(status))
  609. device->flags.lockable = 1;
  610. /* Presence of _PS0|_PR0 indicates 'power manageable' */
  611. status = acpi_get_handle(device->handle, "_PS0", &temp);
  612. if (ACPI_FAILURE(status))
  613. status = acpi_get_handle(device->handle, "_PR0", &temp);
  614. if (ACPI_SUCCESS(status))
  615. device->flags.power_manageable = 1;
  616. /* Presence of _PRW indicates wake capable */
  617. status = acpi_get_handle(device->handle, "_PRW", &temp);
  618. if (ACPI_SUCCESS(status))
  619. device->flags.wake_capable = 1;
  620. /* TBD: Peformance management */
  621. return_VALUE(0);
  622. }
  623. static void acpi_device_get_busid(struct acpi_device *device,
  624. acpi_handle handle, int type)
  625. {
  626. char bus_id[5] = { '?', 0 };
  627. struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
  628. int i = 0;
  629. /*
  630. * Bus ID
  631. * ------
  632. * The device's Bus ID is simply the object name.
  633. * TBD: Shouldn't this value be unique (within the ACPI namespace)?
  634. */
  635. switch (type) {
  636. case ACPI_BUS_TYPE_SYSTEM:
  637. strcpy(device->pnp.bus_id, "ACPI");
  638. break;
  639. case ACPI_BUS_TYPE_POWER_BUTTON:
  640. strcpy(device->pnp.bus_id, "PWRF");
  641. break;
  642. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  643. strcpy(device->pnp.bus_id, "SLPF");
  644. break;
  645. default:
  646. acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
  647. /* Clean up trailing underscores (if any) */
  648. for (i = 3; i > 1; i--) {
  649. if (bus_id[i] == '_')
  650. bus_id[i] = '\0';
  651. else
  652. break;
  653. }
  654. strcpy(device->pnp.bus_id, bus_id);
  655. break;
  656. }
  657. }
  658. static void acpi_device_set_id(struct acpi_device *device,
  659. struct acpi_device *parent, acpi_handle handle,
  660. int type)
  661. {
  662. struct acpi_device_info *info;
  663. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  664. char *hid = NULL;
  665. char *uid = NULL;
  666. struct acpi_compatible_id_list *cid_list = NULL;
  667. acpi_status status;
  668. switch (type) {
  669. case ACPI_BUS_TYPE_DEVICE:
  670. status = acpi_get_object_info(handle, &buffer);
  671. if (ACPI_FAILURE(status)) {
  672. printk("%s: Error reading device info\n", __FUNCTION__);
  673. return;
  674. }
  675. info = buffer.pointer;
  676. if (info->valid & ACPI_VALID_HID)
  677. hid = info->hardware_id.value;
  678. if (info->valid & ACPI_VALID_UID)
  679. uid = info->unique_id.value;
  680. if (info->valid & ACPI_VALID_CID)
  681. cid_list = &info->compatibility_id;
  682. if (info->valid & ACPI_VALID_ADR) {
  683. device->pnp.bus_address = info->address;
  684. device->flags.bus_address = 1;
  685. }
  686. break;
  687. case ACPI_BUS_TYPE_POWER:
  688. hid = ACPI_POWER_HID;
  689. break;
  690. case ACPI_BUS_TYPE_PROCESSOR:
  691. hid = ACPI_PROCESSOR_HID;
  692. break;
  693. case ACPI_BUS_TYPE_SYSTEM:
  694. hid = ACPI_SYSTEM_HID;
  695. break;
  696. case ACPI_BUS_TYPE_THERMAL:
  697. hid = ACPI_THERMAL_HID;
  698. break;
  699. case ACPI_BUS_TYPE_POWER_BUTTON:
  700. hid = ACPI_BUTTON_HID_POWERF;
  701. break;
  702. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  703. hid = ACPI_BUTTON_HID_SLEEPF;
  704. break;
  705. }
  706. /*
  707. * \_SB
  708. * ----
  709. * Fix for the system root bus device -- the only root-level device.
  710. */
  711. if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
  712. hid = ACPI_BUS_HID;
  713. strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
  714. strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
  715. }
  716. if (hid) {
  717. strcpy(device->pnp.hardware_id, hid);
  718. device->flags.hardware_id = 1;
  719. }
  720. if (uid) {
  721. strcpy(device->pnp.unique_id, uid);
  722. device->flags.unique_id = 1;
  723. }
  724. if (cid_list) {
  725. device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
  726. if (device->pnp.cid_list)
  727. memcpy(device->pnp.cid_list, cid_list, cid_list->size);
  728. else
  729. printk(KERN_ERR "Memory allocation error\n");
  730. }
  731. acpi_os_free(buffer.pointer);
  732. }
  733. static int acpi_device_set_context(struct acpi_device *device, int type)
  734. {
  735. acpi_status status = AE_OK;
  736. int result = 0;
  737. /*
  738. * Context
  739. * -------
  740. * Attach this 'struct acpi_device' to the ACPI object. This makes
  741. * resolutions from handle->device very efficient. Note that we need
  742. * to be careful with fixed-feature devices as they all attach to the
  743. * root object.
  744. */
  745. if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
  746. type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
  747. status = acpi_attach_data(device->handle,
  748. acpi_bus_data_handler, device);
  749. if (ACPI_FAILURE(status)) {
  750. printk("Error attaching device data\n");
  751. result = -ENODEV;
  752. }
  753. }
  754. return result;
  755. }
  756. static void acpi_device_get_debug_info(struct acpi_device *device,
  757. acpi_handle handle, int type)
  758. {
  759. #ifdef CONFIG_ACPI_DEBUG_OUTPUT
  760. char *type_string = NULL;
  761. char name[80] = { '?', '\0' };
  762. struct acpi_buffer buffer = { sizeof(name), name };
  763. switch (type) {
  764. case ACPI_BUS_TYPE_DEVICE:
  765. type_string = "Device";
  766. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  767. break;
  768. case ACPI_BUS_TYPE_POWER:
  769. type_string = "Power Resource";
  770. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  771. break;
  772. case ACPI_BUS_TYPE_PROCESSOR:
  773. type_string = "Processor";
  774. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  775. break;
  776. case ACPI_BUS_TYPE_SYSTEM:
  777. type_string = "System";
  778. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  779. break;
  780. case ACPI_BUS_TYPE_THERMAL:
  781. type_string = "Thermal Zone";
  782. acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
  783. break;
  784. case ACPI_BUS_TYPE_POWER_BUTTON:
  785. type_string = "Power Button";
  786. sprintf(name, "PWRB");
  787. break;
  788. case ACPI_BUS_TYPE_SLEEP_BUTTON:
  789. type_string = "Sleep Button";
  790. sprintf(name, "SLPB");
  791. break;
  792. }
  793. printk(KERN_DEBUG "Found %s %s [%p]\n", type_string, name, handle);
  794. #endif /*CONFIG_ACPI_DEBUG_OUTPUT */
  795. }
  796. static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
  797. {
  798. int result = 0;
  799. struct acpi_driver *driver;
  800. ACPI_FUNCTION_TRACE("acpi_bus_remove");
  801. if (!dev)
  802. return_VALUE(-EINVAL);
  803. driver = dev->driver;
  804. if ((driver) && (driver->ops.remove)) {
  805. if (driver->ops.stop) {
  806. result = driver->ops.stop(dev, ACPI_BUS_REMOVAL_EJECT);
  807. if (result)
  808. return_VALUE(result);
  809. }
  810. result = dev->driver->ops.remove(dev, ACPI_BUS_REMOVAL_EJECT);
  811. if (result) {
  812. return_VALUE(result);
  813. }
  814. atomic_dec(&dev->driver->references);
  815. dev->driver = NULL;
  816. acpi_driver_data(dev) = NULL;
  817. }
  818. if (!rmdevice)
  819. return_VALUE(0);
  820. if (dev->flags.bus_address) {
  821. if ((dev->parent) && (dev->parent->ops.unbind))
  822. dev->parent->ops.unbind(dev);
  823. }
  824. acpi_device_unregister(dev, ACPI_BUS_REMOVAL_EJECT);
  825. return_VALUE(0);
  826. }
  827. static int
  828. acpi_add_single_object(struct acpi_device **child,
  829. struct acpi_device *parent, acpi_handle handle, int type)
  830. {
  831. int result = 0;
  832. struct acpi_device *device = NULL;
  833. ACPI_FUNCTION_TRACE("acpi_add_single_object");
  834. if (!child)
  835. return_VALUE(-EINVAL);
  836. device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL);
  837. if (!device) {
  838. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Memory allocation error\n"));
  839. return_VALUE(-ENOMEM);
  840. }
  841. memset(device, 0, sizeof(struct acpi_device));
  842. device->handle = handle;
  843. device->parent = parent;
  844. acpi_device_get_busid(device, handle, type);
  845. /*
  846. * Flags
  847. * -----
  848. * Get prior to calling acpi_bus_get_status() so we know whether
  849. * or not _STA is present. Note that we only look for object
  850. * handles -- cannot evaluate objects until we know the device is
  851. * present and properly initialized.
  852. */
  853. result = acpi_bus_get_flags(device);
  854. if (result)
  855. goto end;
  856. /*
  857. * Status
  858. * ------
  859. * See if the device is present. We always assume that non-Device
  860. * and non-Processor objects (e.g. thermal zones, power resources,
  861. * etc.) are present, functioning, etc. (at least when parent object
  862. * is present). Note that _STA has a different meaning for some
  863. * objects (e.g. power resources) so we need to be careful how we use
  864. * it.
  865. */
  866. switch (type) {
  867. case ACPI_BUS_TYPE_PROCESSOR:
  868. case ACPI_BUS_TYPE_DEVICE:
  869. result = acpi_bus_get_status(device);
  870. if (ACPI_FAILURE(result) || !device->status.present) {
  871. result = -ENOENT;
  872. goto end;
  873. }
  874. break;
  875. default:
  876. STRUCT_TO_INT(device->status) = 0x0F;
  877. break;
  878. }
  879. /*
  880. * Initialize Device
  881. * -----------------
  882. * TBD: Synch with Core's enumeration/initialization process.
  883. */
  884. /*
  885. * Hardware ID, Unique ID, & Bus Address
  886. * -------------------------------------
  887. */
  888. acpi_device_set_id(device, parent, handle, type);
  889. /*
  890. * Power Management
  891. * ----------------
  892. */
  893. if (device->flags.power_manageable) {
  894. result = acpi_bus_get_power_flags(device);
  895. if (result)
  896. goto end;
  897. }
  898. /*
  899. * Wakeup device management
  900. *-----------------------
  901. */
  902. if (device->flags.wake_capable) {
  903. result = acpi_bus_get_wakeup_device_flags(device);
  904. if (result)
  905. goto end;
  906. }
  907. /*
  908. * Performance Management
  909. * ----------------------
  910. */
  911. if (device->flags.performance_manageable) {
  912. result = acpi_bus_get_perf_flags(device);
  913. if (result)
  914. goto end;
  915. }
  916. if ((result = acpi_device_set_context(device, type)))
  917. goto end;
  918. acpi_device_get_debug_info(device, handle, type);
  919. acpi_device_register(device, parent);
  920. /*
  921. * Bind _ADR-Based Devices
  922. * -----------------------
  923. * If there's a a bus address (_ADR) then we utilize the parent's
  924. * 'bind' function (if exists) to bind the ACPI- and natively-
  925. * enumerated device representations.
  926. */
  927. if (device->flags.bus_address) {
  928. if (device->parent && device->parent->ops.bind)
  929. device->parent->ops.bind(device);
  930. }
  931. /*
  932. * Locate & Attach Driver
  933. * ----------------------
  934. * If there's a hardware id (_HID) or compatible ids (_CID) we check
  935. * to see if there's a driver installed for this kind of device. Note
  936. * that drivers can install before or after a device is enumerated.
  937. *
  938. * TBD: Assumes LDM provides driver hot-plug capability.
  939. */
  940. acpi_bus_find_driver(device);
  941. end:
  942. if (!result)
  943. *child = device;
  944. else {
  945. kfree(device->pnp.cid_list);
  946. kfree(device);
  947. }
  948. return_VALUE(result);
  949. }
  950. static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
  951. {
  952. acpi_status status = AE_OK;
  953. struct acpi_device *parent = NULL;
  954. struct acpi_device *child = NULL;
  955. acpi_handle phandle = NULL;
  956. acpi_handle chandle = NULL;
  957. acpi_object_type type = 0;
  958. u32 level = 1;
  959. ACPI_FUNCTION_TRACE("acpi_bus_scan");
  960. if (!start)
  961. return_VALUE(-EINVAL);
  962. parent = start;
  963. phandle = start->handle;
  964. /*
  965. * Parse through the ACPI namespace, identify all 'devices', and
  966. * create a new 'struct acpi_device' for each.
  967. */
  968. while ((level > 0) && parent) {
  969. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  970. chandle, &chandle);
  971. /*
  972. * If this scope is exhausted then move our way back up.
  973. */
  974. if (ACPI_FAILURE(status)) {
  975. level--;
  976. chandle = phandle;
  977. acpi_get_parent(phandle, &phandle);
  978. if (parent->parent)
  979. parent = parent->parent;
  980. continue;
  981. }
  982. status = acpi_get_type(chandle, &type);
  983. if (ACPI_FAILURE(status))
  984. continue;
  985. /*
  986. * If this is a scope object then parse it (depth-first).
  987. */
  988. if (type == ACPI_TYPE_LOCAL_SCOPE) {
  989. level++;
  990. phandle = chandle;
  991. chandle = NULL;
  992. continue;
  993. }
  994. /*
  995. * We're only interested in objects that we consider 'devices'.
  996. */
  997. switch (type) {
  998. case ACPI_TYPE_DEVICE:
  999. type = ACPI_BUS_TYPE_DEVICE;
  1000. break;
  1001. case ACPI_TYPE_PROCESSOR:
  1002. type = ACPI_BUS_TYPE_PROCESSOR;
  1003. break;
  1004. case ACPI_TYPE_THERMAL:
  1005. type = ACPI_BUS_TYPE_THERMAL;
  1006. break;
  1007. case ACPI_TYPE_POWER:
  1008. type = ACPI_BUS_TYPE_POWER;
  1009. break;
  1010. default:
  1011. continue;
  1012. }
  1013. if (ops->acpi_op_add)
  1014. status = acpi_add_single_object(&child, parent,
  1015. chandle, type);
  1016. else
  1017. status = acpi_bus_get_device(chandle, &child);
  1018. if (ACPI_FAILURE(status))
  1019. continue;
  1020. if (ops->acpi_op_start) {
  1021. status = acpi_start_single_object(child);
  1022. if (ACPI_FAILURE(status))
  1023. continue;
  1024. }
  1025. /*
  1026. * If the device is present, enabled, and functioning then
  1027. * parse its scope (depth-first). Note that we need to
  1028. * represent absent devices to facilitate PnP notifications
  1029. * -- but only the subtree head (not all of its children,
  1030. * which will be enumerated when the parent is inserted).
  1031. *
  1032. * TBD: Need notifications and other detection mechanisms
  1033. * in place before we can fully implement this.
  1034. */
  1035. if (child->status.present) {
  1036. status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
  1037. NULL, NULL);
  1038. if (ACPI_SUCCESS(status)) {
  1039. level++;
  1040. phandle = chandle;
  1041. chandle = NULL;
  1042. parent = child;
  1043. }
  1044. }
  1045. }
  1046. return_VALUE(0);
  1047. }
  1048. int
  1049. acpi_bus_add(struct acpi_device **child,
  1050. struct acpi_device *parent, acpi_handle handle, int type)
  1051. {
  1052. int result;
  1053. struct acpi_bus_ops ops;
  1054. ACPI_FUNCTION_TRACE("acpi_bus_add");
  1055. result = acpi_add_single_object(child, parent, handle, type);
  1056. if (!result) {
  1057. memset(&ops, 0, sizeof(ops));
  1058. ops.acpi_op_add = 1;
  1059. result = acpi_bus_scan(*child, &ops);
  1060. }
  1061. return_VALUE(result);
  1062. }
  1063. EXPORT_SYMBOL(acpi_bus_add);
  1064. int acpi_bus_start(struct acpi_device *device)
  1065. {
  1066. int result;
  1067. struct acpi_bus_ops ops;
  1068. ACPI_FUNCTION_TRACE("acpi_bus_start");
  1069. if (!device)
  1070. return_VALUE(-EINVAL);
  1071. result = acpi_start_single_object(device);
  1072. if (!result) {
  1073. memset(&ops, 0, sizeof(ops));
  1074. ops.acpi_op_start = 1;
  1075. result = acpi_bus_scan(device, &ops);
  1076. }
  1077. return_VALUE(result);
  1078. }
  1079. EXPORT_SYMBOL(acpi_bus_start);
  1080. static int acpi_bus_trim(struct acpi_device *start, int rmdevice)
  1081. {
  1082. acpi_status status;
  1083. struct acpi_device *parent, *child;
  1084. acpi_handle phandle, chandle;
  1085. acpi_object_type type;
  1086. u32 level = 1;
  1087. int err = 0;
  1088. parent = start;
  1089. phandle = start->handle;
  1090. child = chandle = NULL;
  1091. while ((level > 0) && parent && (!err)) {
  1092. status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
  1093. chandle, &chandle);
  1094. /*
  1095. * If this scope is exhausted then move our way back up.
  1096. */
  1097. if (ACPI_FAILURE(status)) {
  1098. level--;
  1099. chandle = phandle;
  1100. acpi_get_parent(phandle, &phandle);
  1101. child = parent;
  1102. parent = parent->parent;
  1103. if (level == 0)
  1104. err = acpi_bus_remove(child, rmdevice);
  1105. else
  1106. err = acpi_bus_remove(child, 1);
  1107. continue;
  1108. }
  1109. status = acpi_get_type(chandle, &type);
  1110. if (ACPI_FAILURE(status)) {
  1111. continue;
  1112. }
  1113. /*
  1114. * If there is a device corresponding to chandle then
  1115. * parse it (depth-first).
  1116. */
  1117. if (acpi_bus_get_device(chandle, &child) == 0) {
  1118. level++;
  1119. phandle = chandle;
  1120. chandle = NULL;
  1121. parent = child;
  1122. }
  1123. continue;
  1124. }
  1125. return err;
  1126. }
  1127. static int acpi_bus_scan_fixed(struct acpi_device *root)
  1128. {
  1129. int result = 0;
  1130. struct acpi_device *device = NULL;
  1131. ACPI_FUNCTION_TRACE("acpi_bus_scan_fixed");
  1132. if (!root)
  1133. return_VALUE(-ENODEV);
  1134. /*
  1135. * Enumerate all fixed-feature devices.
  1136. */
  1137. if (acpi_fadt.pwr_button == 0) {
  1138. result = acpi_add_single_object(&device, acpi_root,
  1139. NULL,
  1140. ACPI_BUS_TYPE_POWER_BUTTON);
  1141. if (!result)
  1142. result = acpi_start_single_object(device);
  1143. }
  1144. if (acpi_fadt.sleep_button == 0) {
  1145. result = acpi_add_single_object(&device, acpi_root,
  1146. NULL,
  1147. ACPI_BUS_TYPE_SLEEP_BUTTON);
  1148. if (!result)
  1149. result = acpi_start_single_object(device);
  1150. }
  1151. return_VALUE(result);
  1152. }
  1153. static int __init acpi_scan_init(void)
  1154. {
  1155. int result;
  1156. struct acpi_bus_ops ops;
  1157. ACPI_FUNCTION_TRACE("acpi_scan_init");
  1158. if (acpi_disabled)
  1159. return_VALUE(0);
  1160. kset_register(&acpi_namespace_kset);
  1161. /*
  1162. * Create the root device in the bus's device tree
  1163. */
  1164. result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
  1165. ACPI_BUS_TYPE_SYSTEM);
  1166. if (result)
  1167. goto Done;
  1168. result = acpi_start_single_object(acpi_root);
  1169. /*
  1170. * Enumerate devices in the ACPI namespace.
  1171. */
  1172. result = acpi_bus_scan_fixed(acpi_root);
  1173. if (!result) {
  1174. memset(&ops, 0, sizeof(ops));
  1175. ops.acpi_op_add = 1;
  1176. ops.acpi_op_start = 1;
  1177. result = acpi_bus_scan(acpi_root, &ops);
  1178. }
  1179. if (result)
  1180. acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
  1181. Done:
  1182. return_VALUE(result);
  1183. }
  1184. subsys_initcall(acpi_scan_init);