bus.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. /*
  2. * acpi_bus.c - ACPI Bus Driver ($Revision: 80 $)
  3. *
  4. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  5. *
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/kernel.h>
  28. #include <linux/list.h>
  29. #include <linux/sched.h>
  30. #include <linux/pm.h>
  31. #include <linux/device.h>
  32. #include <linux/proc_fs.h>
  33. #include <linux/acpi.h>
  34. #ifdef CONFIG_X86
  35. #include <asm/mpspec.h>
  36. #endif
  37. #include <linux/pci.h>
  38. #include <acpi/acpi_bus.h>
  39. #include <acpi/acpi_drivers.h>
  40. #include <linux/dmi.h>
  41. #include "internal.h"
  42. #define _COMPONENT ACPI_BUS_COMPONENT
  43. ACPI_MODULE_NAME("bus");
  44. struct acpi_device *acpi_root;
  45. struct proc_dir_entry *acpi_root_dir;
  46. EXPORT_SYMBOL(acpi_root_dir);
  47. #define STRUCT_TO_INT(s) (*((int*)&s))
  48. static int set_power_nocheck(const struct dmi_system_id *id)
  49. {
  50. printk(KERN_NOTICE PREFIX "%s detected - "
  51. "disable power check in power transistion\n", id->ident);
  52. acpi_power_nocheck = 1;
  53. return 0;
  54. }
  55. static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
  56. {
  57. set_power_nocheck, "HP Pavilion 05", {
  58. DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
  59. DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
  60. DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
  61. {},
  62. };
  63. /* --------------------------------------------------------------------------
  64. Device Management
  65. -------------------------------------------------------------------------- */
  66. int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
  67. {
  68. acpi_status status = AE_OK;
  69. if (!device)
  70. return -EINVAL;
  71. /* TBD: Support fixed-feature devices */
  72. status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
  73. if (ACPI_FAILURE(status) || !*device) {
  74. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  75. handle));
  76. return -ENODEV;
  77. }
  78. return 0;
  79. }
  80. EXPORT_SYMBOL(acpi_bus_get_device);
  81. acpi_status acpi_bus_get_status_handle(acpi_handle handle,
  82. unsigned long long *sta)
  83. {
  84. acpi_status status;
  85. status = acpi_evaluate_integer(handle, "_STA", NULL, sta);
  86. if (ACPI_SUCCESS(status))
  87. return AE_OK;
  88. if (status == AE_NOT_FOUND) {
  89. *sta = ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
  90. ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING;
  91. return AE_OK;
  92. }
  93. return status;
  94. }
  95. int acpi_bus_get_status(struct acpi_device *device)
  96. {
  97. acpi_status status;
  98. unsigned long long sta;
  99. status = acpi_bus_get_status_handle(device->handle, &sta);
  100. if (ACPI_FAILURE(status))
  101. return -ENODEV;
  102. STRUCT_TO_INT(device->status) = (int) sta;
  103. if (device->status.functional && !device->status.present) {
  104. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
  105. "functional but not present;\n",
  106. device->pnp.bus_id,
  107. (u32) STRUCT_TO_INT(device->status)));
  108. }
  109. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
  110. device->pnp.bus_id,
  111. (u32) STRUCT_TO_INT(device->status)));
  112. return 0;
  113. }
  114. EXPORT_SYMBOL(acpi_bus_get_status);
  115. void acpi_bus_private_data_handler(acpi_handle handle,
  116. void *context)
  117. {
  118. return;
  119. }
  120. EXPORT_SYMBOL(acpi_bus_private_data_handler);
  121. int acpi_bus_get_private_data(acpi_handle handle, void **data)
  122. {
  123. acpi_status status = AE_OK;
  124. if (!*data)
  125. return -EINVAL;
  126. status = acpi_get_data(handle, acpi_bus_private_data_handler, data);
  127. if (ACPI_FAILURE(status) || !*data) {
  128. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
  129. handle));
  130. return -ENODEV;
  131. }
  132. return 0;
  133. }
  134. EXPORT_SYMBOL(acpi_bus_get_private_data);
  135. /* --------------------------------------------------------------------------
  136. Power Management
  137. -------------------------------------------------------------------------- */
  138. int acpi_bus_get_power(acpi_handle handle, int *state)
  139. {
  140. int result = 0;
  141. acpi_status status = 0;
  142. struct acpi_device *device = NULL;
  143. unsigned long long psc = 0;
  144. result = acpi_bus_get_device(handle, &device);
  145. if (result)
  146. return result;
  147. *state = ACPI_STATE_UNKNOWN;
  148. if (!device->flags.power_manageable) {
  149. /* TBD: Non-recursive algorithm for walking up hierarchy */
  150. if (device->parent)
  151. *state = device->parent->power.state;
  152. else
  153. *state = ACPI_STATE_D0;
  154. } else {
  155. /*
  156. * Get the device's power state either directly (via _PSC) or
  157. * indirectly (via power resources).
  158. */
  159. if (device->power.flags.explicit_get) {
  160. status = acpi_evaluate_integer(device->handle, "_PSC",
  161. NULL, &psc);
  162. if (ACPI_FAILURE(status))
  163. return -ENODEV;
  164. device->power.state = (int)psc;
  165. } else if (device->power.flags.power_resources) {
  166. result = acpi_power_get_inferred_state(device);
  167. if (result)
  168. return result;
  169. }
  170. *state = device->power.state;
  171. }
  172. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
  173. device->pnp.bus_id, device->power.state));
  174. return 0;
  175. }
  176. EXPORT_SYMBOL(acpi_bus_get_power);
  177. int acpi_bus_set_power(acpi_handle handle, int state)
  178. {
  179. int result = 0;
  180. acpi_status status = AE_OK;
  181. struct acpi_device *device = NULL;
  182. char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
  183. result = acpi_bus_get_device(handle, &device);
  184. if (result)
  185. return result;
  186. if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
  187. return -EINVAL;
  188. /* Make sure this is a valid target state */
  189. if (!device->flags.power_manageable) {
  190. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
  191. kobject_name(&device->dev.kobj)));
  192. return -ENODEV;
  193. }
  194. /*
  195. * Get device's current power state
  196. */
  197. if (!acpi_power_nocheck) {
  198. /*
  199. * Maybe the incorrect power state is returned on the bogus
  200. * bios, which is different with the real power state.
  201. * For example: the bios returns D0 state and the real power
  202. * state is D3. OS expects to set the device to D0 state. In
  203. * such case if OS uses the power state returned by the BIOS,
  204. * the device can't be transisted to the correct power state.
  205. * So if the acpi_power_nocheck is set, it is unnecessary to
  206. * get the power state by calling acpi_bus_get_power.
  207. */
  208. acpi_bus_get_power(device->handle, &device->power.state);
  209. }
  210. if ((state == device->power.state) && !device->flags.force_power_state) {
  211. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
  212. state));
  213. return 0;
  214. }
  215. if (!device->power.states[state].flags.valid) {
  216. printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
  217. return -ENODEV;
  218. }
  219. if (device->parent && (state < device->parent->power.state)) {
  220. printk(KERN_WARNING PREFIX
  221. "Cannot set device to a higher-powered"
  222. " state than parent\n");
  223. return -ENODEV;
  224. }
  225. /*
  226. * Transition Power
  227. * ----------------
  228. * On transitions to a high-powered state we first apply power (via
  229. * power resources) then evalute _PSx. Conversly for transitions to
  230. * a lower-powered state.
  231. */
  232. if (state < device->power.state) {
  233. if (device->power.flags.power_resources) {
  234. result = acpi_power_transition(device, state);
  235. if (result)
  236. goto end;
  237. }
  238. if (device->power.states[state].flags.explicit_set) {
  239. status = acpi_evaluate_object(device->handle,
  240. object_name, NULL, NULL);
  241. if (ACPI_FAILURE(status)) {
  242. result = -ENODEV;
  243. goto end;
  244. }
  245. }
  246. } else {
  247. if (device->power.states[state].flags.explicit_set) {
  248. status = acpi_evaluate_object(device->handle,
  249. object_name, NULL, NULL);
  250. if (ACPI_FAILURE(status)) {
  251. result = -ENODEV;
  252. goto end;
  253. }
  254. }
  255. if (device->power.flags.power_resources) {
  256. result = acpi_power_transition(device, state);
  257. if (result)
  258. goto end;
  259. }
  260. }
  261. end:
  262. if (result)
  263. printk(KERN_WARNING PREFIX
  264. "Device [%s] failed to transition to D%d\n",
  265. device->pnp.bus_id, state);
  266. else {
  267. device->power.state = state;
  268. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  269. "Device [%s] transitioned to D%d\n",
  270. device->pnp.bus_id, state));
  271. }
  272. return result;
  273. }
  274. EXPORT_SYMBOL(acpi_bus_set_power);
  275. bool acpi_bus_power_manageable(acpi_handle handle)
  276. {
  277. struct acpi_device *device;
  278. int result;
  279. result = acpi_bus_get_device(handle, &device);
  280. return result ? false : device->flags.power_manageable;
  281. }
  282. EXPORT_SYMBOL(acpi_bus_power_manageable);
  283. bool acpi_bus_can_wakeup(acpi_handle handle)
  284. {
  285. struct acpi_device *device;
  286. int result;
  287. result = acpi_bus_get_device(handle, &device);
  288. return result ? false : device->wakeup.flags.valid;
  289. }
  290. EXPORT_SYMBOL(acpi_bus_can_wakeup);
  291. static void acpi_print_osc_error(acpi_handle handle,
  292. struct acpi_osc_context *context, char *error)
  293. {
  294. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER};
  295. int i;
  296. if (ACPI_FAILURE(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer)))
  297. printk(KERN_DEBUG "%s\n", error);
  298. else {
  299. printk(KERN_DEBUG "%s:%s\n", (char *)buffer.pointer, error);
  300. kfree(buffer.pointer);
  301. }
  302. printk(KERN_DEBUG"_OSC request data:");
  303. for (i = 0; i < context->cap.length; i += sizeof(u32))
  304. printk("%x ", *((u32 *)(context->cap.pointer + i)));
  305. printk("\n");
  306. }
  307. static u8 hex_val(unsigned char c)
  308. {
  309. return isdigit(c) ? c - '0' : toupper(c) - 'A' + 10;
  310. }
  311. static acpi_status acpi_str_to_uuid(char *str, u8 *uuid)
  312. {
  313. int i;
  314. static int opc_map_to_uuid[16] = {6, 4, 2, 0, 11, 9, 16, 14, 19, 21,
  315. 24, 26, 28, 30, 32, 34};
  316. if (strlen(str) != 36)
  317. return AE_BAD_PARAMETER;
  318. for (i = 0; i < 36; i++) {
  319. if (i == 8 || i == 13 || i == 18 || i == 23) {
  320. if (str[i] != '-')
  321. return AE_BAD_PARAMETER;
  322. } else if (!isxdigit(str[i]))
  323. return AE_BAD_PARAMETER;
  324. }
  325. for (i = 0; i < 16; i++) {
  326. uuid[i] = hex_val(str[opc_map_to_uuid[i]]) << 4;
  327. uuid[i] |= hex_val(str[opc_map_to_uuid[i] + 1]);
  328. }
  329. return AE_OK;
  330. }
  331. acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
  332. {
  333. acpi_status status;
  334. struct acpi_object_list input;
  335. union acpi_object in_params[4];
  336. union acpi_object *out_obj;
  337. u8 uuid[16];
  338. u32 errors;
  339. struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
  340. if (!context)
  341. return AE_ERROR;
  342. if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
  343. return AE_ERROR;
  344. context->ret.length = ACPI_ALLOCATE_BUFFER;
  345. context->ret.pointer = NULL;
  346. /* Setting up input parameters */
  347. input.count = 4;
  348. input.pointer = in_params;
  349. in_params[0].type = ACPI_TYPE_BUFFER;
  350. in_params[0].buffer.length = 16;
  351. in_params[0].buffer.pointer = uuid;
  352. in_params[1].type = ACPI_TYPE_INTEGER;
  353. in_params[1].integer.value = context->rev;
  354. in_params[2].type = ACPI_TYPE_INTEGER;
  355. in_params[2].integer.value = context->cap.length/sizeof(u32);
  356. in_params[3].type = ACPI_TYPE_BUFFER;
  357. in_params[3].buffer.length = context->cap.length;
  358. in_params[3].buffer.pointer = context->cap.pointer;
  359. status = acpi_evaluate_object(handle, "_OSC", &input, &output);
  360. if (ACPI_FAILURE(status))
  361. return status;
  362. if (!output.length)
  363. return AE_NULL_OBJECT;
  364. out_obj = output.pointer;
  365. if (out_obj->type != ACPI_TYPE_BUFFER
  366. || out_obj->buffer.length != context->cap.length) {
  367. acpi_print_osc_error(handle, context,
  368. "_OSC evaluation returned wrong type");
  369. status = AE_TYPE;
  370. goto out_kfree;
  371. }
  372. /* Need to ignore the bit0 in result code */
  373. errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
  374. if (errors) {
  375. if (errors & OSC_REQUEST_ERROR)
  376. acpi_print_osc_error(handle, context,
  377. "_OSC request failed");
  378. if (errors & OSC_INVALID_UUID_ERROR)
  379. acpi_print_osc_error(handle, context,
  380. "_OSC invalid UUID");
  381. if (errors & OSC_INVALID_REVISION_ERROR)
  382. acpi_print_osc_error(handle, context,
  383. "_OSC invalid revision");
  384. if (errors & OSC_CAPABILITIES_MASK_ERROR) {
  385. if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
  386. & OSC_QUERY_ENABLE)
  387. goto out_success;
  388. status = AE_SUPPORT;
  389. goto out_kfree;
  390. }
  391. status = AE_ERROR;
  392. goto out_kfree;
  393. }
  394. out_success:
  395. context->ret.length = out_obj->buffer.length;
  396. context->ret.pointer = kmalloc(context->ret.length, GFP_KERNEL);
  397. if (!context->ret.pointer) {
  398. status = AE_NO_MEMORY;
  399. goto out_kfree;
  400. }
  401. memcpy(context->ret.pointer, out_obj->buffer.pointer,
  402. context->ret.length);
  403. status = AE_OK;
  404. out_kfree:
  405. kfree(output.pointer);
  406. if (status != AE_OK)
  407. context->ret.pointer = NULL;
  408. return status;
  409. }
  410. EXPORT_SYMBOL(acpi_run_osc);
  411. static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
  412. static void acpi_bus_osc_support(void)
  413. {
  414. u32 capbuf[2];
  415. struct acpi_osc_context context = {
  416. .uuid_str = sb_uuid_str,
  417. .rev = 1,
  418. .cap.length = 8,
  419. .cap.pointer = capbuf,
  420. };
  421. acpi_handle handle;
  422. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  423. capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
  424. #ifdef CONFIG_ACPI_PROCESSOR_AGGREGATOR
  425. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
  426. #endif
  427. if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
  428. return;
  429. if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
  430. kfree(context.ret.pointer);
  431. /* do we need to check the returned cap? Sounds no */
  432. }
  433. /* --------------------------------------------------------------------------
  434. Event Management
  435. -------------------------------------------------------------------------- */
  436. #ifdef CONFIG_ACPI_PROC_EVENT
  437. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  438. LIST_HEAD(acpi_bus_event_list);
  439. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  440. extern int event_is_open;
  441. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  442. {
  443. struct acpi_bus_event *event;
  444. unsigned long flags = 0;
  445. /* drop event on the floor if no one's listening */
  446. if (!event_is_open)
  447. return 0;
  448. event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  449. if (!event)
  450. return -ENOMEM;
  451. strcpy(event->device_class, device_class);
  452. strcpy(event->bus_id, bus_id);
  453. event->type = type;
  454. event->data = data;
  455. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  456. list_add_tail(&event->node, &acpi_bus_event_list);
  457. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  458. wake_up_interruptible(&acpi_bus_event_queue);
  459. return 0;
  460. }
  461. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  462. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  463. {
  464. if (!device)
  465. return -EINVAL;
  466. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  467. device->pnp.bus_id, type, data);
  468. }
  469. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  470. int acpi_bus_receive_event(struct acpi_bus_event *event)
  471. {
  472. unsigned long flags = 0;
  473. struct acpi_bus_event *entry = NULL;
  474. DECLARE_WAITQUEUE(wait, current);
  475. if (!event)
  476. return -EINVAL;
  477. if (list_empty(&acpi_bus_event_list)) {
  478. set_current_state(TASK_INTERRUPTIBLE);
  479. add_wait_queue(&acpi_bus_event_queue, &wait);
  480. if (list_empty(&acpi_bus_event_list))
  481. schedule();
  482. remove_wait_queue(&acpi_bus_event_queue, &wait);
  483. set_current_state(TASK_RUNNING);
  484. if (signal_pending(current))
  485. return -ERESTARTSYS;
  486. }
  487. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  488. if (!list_empty(&acpi_bus_event_list)) {
  489. entry = list_entry(acpi_bus_event_list.next,
  490. struct acpi_bus_event, node);
  491. list_del(&entry->node);
  492. }
  493. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  494. if (!entry)
  495. return -ENODEV;
  496. memcpy(event, entry, sizeof(struct acpi_bus_event));
  497. kfree(entry);
  498. return 0;
  499. }
  500. #endif /* CONFIG_ACPI_PROC_EVENT */
  501. /* --------------------------------------------------------------------------
  502. Notification Handling
  503. -------------------------------------------------------------------------- */
  504. static void acpi_bus_check_device(acpi_handle handle)
  505. {
  506. struct acpi_device *device;
  507. acpi_status status;
  508. struct acpi_device_status old_status;
  509. if (acpi_bus_get_device(handle, &device))
  510. return;
  511. if (!device)
  512. return;
  513. old_status = device->status;
  514. /*
  515. * Make sure this device's parent is present before we go about
  516. * messing with the device.
  517. */
  518. if (device->parent && !device->parent->status.present) {
  519. device->status = device->parent->status;
  520. return;
  521. }
  522. status = acpi_bus_get_status(device);
  523. if (ACPI_FAILURE(status))
  524. return;
  525. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  526. return;
  527. /*
  528. * Device Insertion/Removal
  529. */
  530. if ((device->status.present) && !(old_status.present)) {
  531. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  532. /* TBD: Handle device insertion */
  533. } else if (!(device->status.present) && (old_status.present)) {
  534. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  535. /* TBD: Handle device removal */
  536. }
  537. }
  538. static void acpi_bus_check_scope(acpi_handle handle)
  539. {
  540. /* Status Change? */
  541. acpi_bus_check_device(handle);
  542. /*
  543. * TBD: Enumerate child devices within this device's scope and
  544. * run acpi_bus_check_device()'s on them.
  545. */
  546. }
  547. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  548. int register_acpi_bus_notifier(struct notifier_block *nb)
  549. {
  550. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  551. }
  552. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  553. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  554. {
  555. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  556. }
  557. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  558. /**
  559. * acpi_bus_notify
  560. * ---------------
  561. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  562. */
  563. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  564. {
  565. struct acpi_device *device = NULL;
  566. struct acpi_driver *driver;
  567. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  568. type, handle));
  569. blocking_notifier_call_chain(&acpi_bus_notify_list,
  570. type, (void *)handle);
  571. switch (type) {
  572. case ACPI_NOTIFY_BUS_CHECK:
  573. acpi_bus_check_scope(handle);
  574. /*
  575. * TBD: We'll need to outsource certain events to non-ACPI
  576. * drivers via the device manager (device.c).
  577. */
  578. break;
  579. case ACPI_NOTIFY_DEVICE_CHECK:
  580. acpi_bus_check_device(handle);
  581. /*
  582. * TBD: We'll need to outsource certain events to non-ACPI
  583. * drivers via the device manager (device.c).
  584. */
  585. break;
  586. case ACPI_NOTIFY_DEVICE_WAKE:
  587. /* TBD */
  588. break;
  589. case ACPI_NOTIFY_EJECT_REQUEST:
  590. /* TBD */
  591. break;
  592. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  593. /* TBD: Exactly what does 'light' mean? */
  594. break;
  595. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  596. /* TBD */
  597. break;
  598. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  599. /* TBD */
  600. break;
  601. case ACPI_NOTIFY_POWER_FAULT:
  602. /* TBD */
  603. break;
  604. default:
  605. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  606. "Received unknown/unsupported notification [%08x]\n",
  607. type));
  608. break;
  609. }
  610. acpi_bus_get_device(handle, &device);
  611. if (device) {
  612. driver = device->driver;
  613. if (driver && driver->ops.notify &&
  614. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  615. driver->ops.notify(device, type);
  616. }
  617. }
  618. /* --------------------------------------------------------------------------
  619. Initialization/Cleanup
  620. -------------------------------------------------------------------------- */
  621. static int __init acpi_bus_init_irq(void)
  622. {
  623. acpi_status status = AE_OK;
  624. union acpi_object arg = { ACPI_TYPE_INTEGER };
  625. struct acpi_object_list arg_list = { 1, &arg };
  626. char *message = NULL;
  627. /*
  628. * Let the system know what interrupt model we are using by
  629. * evaluating the \_PIC object, if exists.
  630. */
  631. switch (acpi_irq_model) {
  632. case ACPI_IRQ_MODEL_PIC:
  633. message = "PIC";
  634. break;
  635. case ACPI_IRQ_MODEL_IOAPIC:
  636. message = "IOAPIC";
  637. break;
  638. case ACPI_IRQ_MODEL_IOSAPIC:
  639. message = "IOSAPIC";
  640. break;
  641. case ACPI_IRQ_MODEL_PLATFORM:
  642. message = "platform specific model";
  643. break;
  644. default:
  645. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  646. return -ENODEV;
  647. }
  648. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  649. arg.integer.value = acpi_irq_model;
  650. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  651. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  652. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  653. return -ENODEV;
  654. }
  655. return 0;
  656. }
  657. u8 acpi_gbl_permanent_mmap;
  658. void __init acpi_early_init(void)
  659. {
  660. acpi_status status = AE_OK;
  661. if (acpi_disabled)
  662. return;
  663. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  664. /* enable workarounds, unless strict ACPI spec. compliance */
  665. if (!acpi_strict)
  666. acpi_gbl_enable_interpreter_slack = TRUE;
  667. acpi_gbl_permanent_mmap = 1;
  668. status = acpi_reallocate_root_table();
  669. if (ACPI_FAILURE(status)) {
  670. printk(KERN_ERR PREFIX
  671. "Unable to reallocate ACPI tables\n");
  672. goto error0;
  673. }
  674. status = acpi_initialize_subsystem();
  675. if (ACPI_FAILURE(status)) {
  676. printk(KERN_ERR PREFIX
  677. "Unable to initialize the ACPI Interpreter\n");
  678. goto error0;
  679. }
  680. status = acpi_load_tables();
  681. if (ACPI_FAILURE(status)) {
  682. printk(KERN_ERR PREFIX
  683. "Unable to load the System Description Tables\n");
  684. goto error0;
  685. }
  686. #ifdef CONFIG_X86
  687. if (!acpi_ioapic) {
  688. /* compatible (0) means level (3) */
  689. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  690. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  691. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  692. }
  693. /* Set PIC-mode SCI trigger type */
  694. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  695. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  696. } else {
  697. /*
  698. * now that acpi_gbl_FADT is initialized,
  699. * update it with result from INT_SRC_OVR parsing
  700. */
  701. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  702. }
  703. #endif
  704. status =
  705. acpi_enable_subsystem(~
  706. (ACPI_NO_HARDWARE_INIT |
  707. ACPI_NO_ACPI_ENABLE));
  708. if (ACPI_FAILURE(status)) {
  709. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  710. goto error0;
  711. }
  712. return;
  713. error0:
  714. disable_acpi();
  715. return;
  716. }
  717. static int __init acpi_bus_init(void)
  718. {
  719. int result = 0;
  720. acpi_status status = AE_OK;
  721. extern acpi_status acpi_os_initialize1(void);
  722. acpi_os_initialize1();
  723. status =
  724. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  725. if (ACPI_FAILURE(status)) {
  726. printk(KERN_ERR PREFIX
  727. "Unable to start the ACPI Interpreter\n");
  728. goto error1;
  729. }
  730. /*
  731. * ACPI 2.0 requires the EC driver to be loaded and work before
  732. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  733. * is called).
  734. *
  735. * This is accomplished by looking for the ECDT table, and getting
  736. * the EC parameters out of that.
  737. */
  738. status = acpi_ec_ecdt_probe();
  739. /* Ignore result. Not having an ECDT is not fatal. */
  740. acpi_bus_osc_support();
  741. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  742. if (ACPI_FAILURE(status)) {
  743. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  744. goto error1;
  745. }
  746. acpi_early_processor_set_pdc();
  747. /*
  748. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  749. * is necessary to enable it as early as possible.
  750. */
  751. acpi_boot_ec_enable();
  752. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  753. /* Initialize sleep structures */
  754. acpi_sleep_init();
  755. /*
  756. * Get the system interrupt model and evaluate \_PIC.
  757. */
  758. result = acpi_bus_init_irq();
  759. if (result)
  760. goto error1;
  761. /*
  762. * Register the for all standard device notifications.
  763. */
  764. status =
  765. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  766. &acpi_bus_notify, NULL);
  767. if (ACPI_FAILURE(status)) {
  768. printk(KERN_ERR PREFIX
  769. "Unable to register for device notifications\n");
  770. goto error1;
  771. }
  772. /*
  773. * Create the top ACPI proc directory
  774. */
  775. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  776. return 0;
  777. /* Mimic structured exception handling */
  778. error1:
  779. acpi_terminate();
  780. return -ENODEV;
  781. }
  782. struct kobject *acpi_kobj;
  783. static int __init acpi_init(void)
  784. {
  785. int result = 0;
  786. if (acpi_disabled) {
  787. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  788. return -ENODEV;
  789. }
  790. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  791. if (!acpi_kobj) {
  792. printk(KERN_WARNING "%s: kset create error\n", __func__);
  793. acpi_kobj = NULL;
  794. }
  795. init_acpi_device_notify();
  796. result = acpi_bus_init();
  797. if (!result) {
  798. pci_mmcfg_late_init();
  799. if (!(pm_flags & PM_APM))
  800. pm_flags |= PM_ACPI;
  801. else {
  802. printk(KERN_INFO PREFIX
  803. "APM is already active, exiting\n");
  804. disable_acpi();
  805. result = -ENODEV;
  806. }
  807. } else
  808. disable_acpi();
  809. if (acpi_disabled)
  810. return result;
  811. /*
  812. * If the laptop falls into the DMI check table, the power state check
  813. * will be disabled in the course of device power transistion.
  814. */
  815. dmi_check_system(power_nocheck_dmi_table);
  816. acpi_scan_init();
  817. acpi_ec_init();
  818. acpi_power_init();
  819. acpi_system_init();
  820. acpi_debug_init();
  821. acpi_sleep_proc_init();
  822. acpi_wakeup_device_init();
  823. return result;
  824. }
  825. subsys_initcall(acpi_init);