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