scan.c 34 KB

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