bus.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  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. if (!context)
  340. return AE_ERROR;
  341. if (ACPI_FAILURE(acpi_str_to_uuid(context->uuid_str, uuid)))
  342. return AE_ERROR;
  343. context->ret.length = ACPI_ALLOCATE_BUFFER;
  344. context->ret.pointer = NULL;
  345. /* Setting up input parameters */
  346. input.count = 4;
  347. input.pointer = in_params;
  348. in_params[0].type = ACPI_TYPE_BUFFER;
  349. in_params[0].buffer.length = 16;
  350. in_params[0].buffer.pointer = uuid;
  351. in_params[1].type = ACPI_TYPE_INTEGER;
  352. in_params[1].integer.value = context->rev;
  353. in_params[2].type = ACPI_TYPE_INTEGER;
  354. in_params[2].integer.value = context->cap.length/sizeof(u32);
  355. in_params[3].type = ACPI_TYPE_BUFFER;
  356. in_params[3].buffer.length = context->cap.length;
  357. in_params[3].buffer.pointer = context->cap.pointer;
  358. status = acpi_evaluate_object(handle, "_OSC", &input, &context->ret);
  359. if (ACPI_FAILURE(status))
  360. return status;
  361. /* return buffer should have the same length as cap buffer */
  362. if (context->ret.length != context->cap.length)
  363. return AE_NULL_OBJECT;
  364. out_obj = context->ret.pointer;
  365. if (out_obj->type != ACPI_TYPE_BUFFER) {
  366. acpi_print_osc_error(handle, context,
  367. "_OSC evaluation returned wrong type");
  368. status = AE_TYPE;
  369. goto out_kfree;
  370. }
  371. /* Need to ignore the bit0 in result code */
  372. errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
  373. if (errors) {
  374. if (errors & OSC_REQUEST_ERROR)
  375. acpi_print_osc_error(handle, context,
  376. "_OSC request failed");
  377. if (errors & OSC_INVALID_UUID_ERROR)
  378. acpi_print_osc_error(handle, context,
  379. "_OSC invalid UUID");
  380. if (errors & OSC_INVALID_REVISION_ERROR)
  381. acpi_print_osc_error(handle, context,
  382. "_OSC invalid revision");
  383. if (errors & OSC_CAPABILITIES_MASK_ERROR) {
  384. if (((u32 *)context->cap.pointer)[OSC_QUERY_TYPE]
  385. & OSC_QUERY_ENABLE)
  386. goto out_success;
  387. status = AE_SUPPORT;
  388. goto out_kfree;
  389. }
  390. status = AE_ERROR;
  391. goto out_kfree;
  392. }
  393. out_success:
  394. return AE_OK;
  395. out_kfree:
  396. kfree(context->ret.pointer);
  397. context->ret.pointer = NULL;
  398. return status;
  399. }
  400. EXPORT_SYMBOL(acpi_run_osc);
  401. static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
  402. static void acpi_bus_osc_support(void)
  403. {
  404. u32 capbuf[2];
  405. struct acpi_osc_context context = {
  406. .uuid_str = sb_uuid_str,
  407. .rev = 1,
  408. .cap.length = 8,
  409. .cap.pointer = capbuf,
  410. };
  411. acpi_handle handle;
  412. capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
  413. capbuf[OSC_SUPPORT_TYPE] = OSC_SB_PR3_SUPPORT; /* _PR3 is in use */
  414. #ifdef CONFIG_ACPI_PROCESSOR_AGGREGATOR
  415. capbuf[OSC_SUPPORT_TYPE] |= OSC_SB_PAD_SUPPORT;
  416. #endif
  417. if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_SB", &handle)))
  418. return;
  419. if (ACPI_SUCCESS(acpi_run_osc(handle, &context)))
  420. kfree(context.ret.pointer);
  421. /* do we need to check the returned cap? Sounds no */
  422. }
  423. /* --------------------------------------------------------------------------
  424. Event Management
  425. -------------------------------------------------------------------------- */
  426. #ifdef CONFIG_ACPI_PROC_EVENT
  427. static DEFINE_SPINLOCK(acpi_bus_event_lock);
  428. LIST_HEAD(acpi_bus_event_list);
  429. DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
  430. extern int event_is_open;
  431. int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data)
  432. {
  433. struct acpi_bus_event *event;
  434. unsigned long flags = 0;
  435. /* drop event on the floor if no one's listening */
  436. if (!event_is_open)
  437. return 0;
  438. event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
  439. if (!event)
  440. return -ENOMEM;
  441. strcpy(event->device_class, device_class);
  442. strcpy(event->bus_id, bus_id);
  443. event->type = type;
  444. event->data = data;
  445. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  446. list_add_tail(&event->node, &acpi_bus_event_list);
  447. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  448. wake_up_interruptible(&acpi_bus_event_queue);
  449. return 0;
  450. }
  451. EXPORT_SYMBOL_GPL(acpi_bus_generate_proc_event4);
  452. int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
  453. {
  454. if (!device)
  455. return -EINVAL;
  456. return acpi_bus_generate_proc_event4(device->pnp.device_class,
  457. device->pnp.bus_id, type, data);
  458. }
  459. EXPORT_SYMBOL(acpi_bus_generate_proc_event);
  460. int acpi_bus_receive_event(struct acpi_bus_event *event)
  461. {
  462. unsigned long flags = 0;
  463. struct acpi_bus_event *entry = NULL;
  464. DECLARE_WAITQUEUE(wait, current);
  465. if (!event)
  466. return -EINVAL;
  467. if (list_empty(&acpi_bus_event_list)) {
  468. set_current_state(TASK_INTERRUPTIBLE);
  469. add_wait_queue(&acpi_bus_event_queue, &wait);
  470. if (list_empty(&acpi_bus_event_list))
  471. schedule();
  472. remove_wait_queue(&acpi_bus_event_queue, &wait);
  473. set_current_state(TASK_RUNNING);
  474. if (signal_pending(current))
  475. return -ERESTARTSYS;
  476. }
  477. spin_lock_irqsave(&acpi_bus_event_lock, flags);
  478. if (!list_empty(&acpi_bus_event_list)) {
  479. entry = list_entry(acpi_bus_event_list.next,
  480. struct acpi_bus_event, node);
  481. list_del(&entry->node);
  482. }
  483. spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
  484. if (!entry)
  485. return -ENODEV;
  486. memcpy(event, entry, sizeof(struct acpi_bus_event));
  487. kfree(entry);
  488. return 0;
  489. }
  490. #endif /* CONFIG_ACPI_PROC_EVENT */
  491. /* --------------------------------------------------------------------------
  492. Notification Handling
  493. -------------------------------------------------------------------------- */
  494. static void acpi_bus_check_device(acpi_handle handle)
  495. {
  496. struct acpi_device *device;
  497. acpi_status status;
  498. struct acpi_device_status old_status;
  499. if (acpi_bus_get_device(handle, &device))
  500. return;
  501. if (!device)
  502. return;
  503. old_status = device->status;
  504. /*
  505. * Make sure this device's parent is present before we go about
  506. * messing with the device.
  507. */
  508. if (device->parent && !device->parent->status.present) {
  509. device->status = device->parent->status;
  510. return;
  511. }
  512. status = acpi_bus_get_status(device);
  513. if (ACPI_FAILURE(status))
  514. return;
  515. if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
  516. return;
  517. /*
  518. * Device Insertion/Removal
  519. */
  520. if ((device->status.present) && !(old_status.present)) {
  521. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device insertion detected\n"));
  522. /* TBD: Handle device insertion */
  523. } else if (!(device->status.present) && (old_status.present)) {
  524. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device removal detected\n"));
  525. /* TBD: Handle device removal */
  526. }
  527. }
  528. static void acpi_bus_check_scope(acpi_handle handle)
  529. {
  530. /* Status Change? */
  531. acpi_bus_check_device(handle);
  532. /*
  533. * TBD: Enumerate child devices within this device's scope and
  534. * run acpi_bus_check_device()'s on them.
  535. */
  536. }
  537. static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
  538. int register_acpi_bus_notifier(struct notifier_block *nb)
  539. {
  540. return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
  541. }
  542. EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
  543. void unregister_acpi_bus_notifier(struct notifier_block *nb)
  544. {
  545. blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
  546. }
  547. EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
  548. /**
  549. * acpi_bus_notify
  550. * ---------------
  551. * Callback for all 'system-level' device notifications (values 0x00-0x7F).
  552. */
  553. static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
  554. {
  555. struct acpi_device *device = NULL;
  556. struct acpi_driver *driver;
  557. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notification %#02x to handle %p\n",
  558. type, handle));
  559. blocking_notifier_call_chain(&acpi_bus_notify_list,
  560. type, (void *)handle);
  561. switch (type) {
  562. case ACPI_NOTIFY_BUS_CHECK:
  563. acpi_bus_check_scope(handle);
  564. /*
  565. * TBD: We'll need to outsource certain events to non-ACPI
  566. * drivers via the device manager (device.c).
  567. */
  568. break;
  569. case ACPI_NOTIFY_DEVICE_CHECK:
  570. acpi_bus_check_device(handle);
  571. /*
  572. * TBD: We'll need to outsource certain events to non-ACPI
  573. * drivers via the device manager (device.c).
  574. */
  575. break;
  576. case ACPI_NOTIFY_DEVICE_WAKE:
  577. /* TBD */
  578. break;
  579. case ACPI_NOTIFY_EJECT_REQUEST:
  580. /* TBD */
  581. break;
  582. case ACPI_NOTIFY_DEVICE_CHECK_LIGHT:
  583. /* TBD: Exactly what does 'light' mean? */
  584. break;
  585. case ACPI_NOTIFY_FREQUENCY_MISMATCH:
  586. /* TBD */
  587. break;
  588. case ACPI_NOTIFY_BUS_MODE_MISMATCH:
  589. /* TBD */
  590. break;
  591. case ACPI_NOTIFY_POWER_FAULT:
  592. /* TBD */
  593. break;
  594. default:
  595. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  596. "Received unknown/unsupported notification [%08x]\n",
  597. type));
  598. break;
  599. }
  600. acpi_bus_get_device(handle, &device);
  601. if (device) {
  602. driver = device->driver;
  603. if (driver && driver->ops.notify &&
  604. (driver->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS))
  605. driver->ops.notify(device, type);
  606. }
  607. }
  608. /* --------------------------------------------------------------------------
  609. Initialization/Cleanup
  610. -------------------------------------------------------------------------- */
  611. static int __init acpi_bus_init_irq(void)
  612. {
  613. acpi_status status = AE_OK;
  614. union acpi_object arg = { ACPI_TYPE_INTEGER };
  615. struct acpi_object_list arg_list = { 1, &arg };
  616. char *message = NULL;
  617. /*
  618. * Let the system know what interrupt model we are using by
  619. * evaluating the \_PIC object, if exists.
  620. */
  621. switch (acpi_irq_model) {
  622. case ACPI_IRQ_MODEL_PIC:
  623. message = "PIC";
  624. break;
  625. case ACPI_IRQ_MODEL_IOAPIC:
  626. message = "IOAPIC";
  627. break;
  628. case ACPI_IRQ_MODEL_IOSAPIC:
  629. message = "IOSAPIC";
  630. break;
  631. case ACPI_IRQ_MODEL_PLATFORM:
  632. message = "platform specific model";
  633. break;
  634. default:
  635. printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
  636. return -ENODEV;
  637. }
  638. printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
  639. arg.integer.value = acpi_irq_model;
  640. status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
  641. if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
  642. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
  643. return -ENODEV;
  644. }
  645. return 0;
  646. }
  647. u8 acpi_gbl_permanent_mmap;
  648. void __init acpi_early_init(void)
  649. {
  650. acpi_status status = AE_OK;
  651. if (acpi_disabled)
  652. return;
  653. printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
  654. /* enable workarounds, unless strict ACPI spec. compliance */
  655. if (!acpi_strict)
  656. acpi_gbl_enable_interpreter_slack = TRUE;
  657. acpi_gbl_permanent_mmap = 1;
  658. status = acpi_reallocate_root_table();
  659. if (ACPI_FAILURE(status)) {
  660. printk(KERN_ERR PREFIX
  661. "Unable to reallocate ACPI tables\n");
  662. goto error0;
  663. }
  664. status = acpi_initialize_subsystem();
  665. if (ACPI_FAILURE(status)) {
  666. printk(KERN_ERR PREFIX
  667. "Unable to initialize the ACPI Interpreter\n");
  668. goto error0;
  669. }
  670. status = acpi_load_tables();
  671. if (ACPI_FAILURE(status)) {
  672. printk(KERN_ERR PREFIX
  673. "Unable to load the System Description Tables\n");
  674. goto error0;
  675. }
  676. #ifdef CONFIG_X86
  677. if (!acpi_ioapic) {
  678. /* compatible (0) means level (3) */
  679. if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
  680. acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
  681. acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
  682. }
  683. /* Set PIC-mode SCI trigger type */
  684. acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
  685. (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
  686. } else {
  687. /*
  688. * now that acpi_gbl_FADT is initialized,
  689. * update it with result from INT_SRC_OVR parsing
  690. */
  691. acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
  692. }
  693. #endif
  694. status =
  695. acpi_enable_subsystem(~
  696. (ACPI_NO_HARDWARE_INIT |
  697. ACPI_NO_ACPI_ENABLE));
  698. if (ACPI_FAILURE(status)) {
  699. printk(KERN_ERR PREFIX "Unable to enable ACPI\n");
  700. goto error0;
  701. }
  702. return;
  703. error0:
  704. disable_acpi();
  705. return;
  706. }
  707. static int __init acpi_bus_init(void)
  708. {
  709. int result = 0;
  710. acpi_status status = AE_OK;
  711. extern acpi_status acpi_os_initialize1(void);
  712. acpi_os_initialize1();
  713. status =
  714. acpi_enable_subsystem(ACPI_NO_HARDWARE_INIT | ACPI_NO_ACPI_ENABLE);
  715. if (ACPI_FAILURE(status)) {
  716. printk(KERN_ERR PREFIX
  717. "Unable to start the ACPI Interpreter\n");
  718. goto error1;
  719. }
  720. /*
  721. * ACPI 2.0 requires the EC driver to be loaded and work before
  722. * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
  723. * is called).
  724. *
  725. * This is accomplished by looking for the ECDT table, and getting
  726. * the EC parameters out of that.
  727. */
  728. status = acpi_ec_ecdt_probe();
  729. /* Ignore result. Not having an ECDT is not fatal. */
  730. acpi_bus_osc_support();
  731. status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
  732. if (ACPI_FAILURE(status)) {
  733. printk(KERN_ERR PREFIX "Unable to initialize ACPI objects\n");
  734. goto error1;
  735. }
  736. acpi_early_processor_set_pdc();
  737. /*
  738. * Maybe EC region is required at bus_scan/acpi_get_devices. So it
  739. * is necessary to enable it as early as possible.
  740. */
  741. acpi_boot_ec_enable();
  742. printk(KERN_INFO PREFIX "Interpreter enabled\n");
  743. /* Initialize sleep structures */
  744. acpi_sleep_init();
  745. /*
  746. * Get the system interrupt model and evaluate \_PIC.
  747. */
  748. result = acpi_bus_init_irq();
  749. if (result)
  750. goto error1;
  751. /*
  752. * Register the for all standard device notifications.
  753. */
  754. status =
  755. acpi_install_notify_handler(ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY,
  756. &acpi_bus_notify, NULL);
  757. if (ACPI_FAILURE(status)) {
  758. printk(KERN_ERR PREFIX
  759. "Unable to register for device notifications\n");
  760. goto error1;
  761. }
  762. /*
  763. * Create the top ACPI proc directory
  764. */
  765. acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
  766. return 0;
  767. /* Mimic structured exception handling */
  768. error1:
  769. acpi_terminate();
  770. return -ENODEV;
  771. }
  772. struct kobject *acpi_kobj;
  773. static int __init acpi_init(void)
  774. {
  775. int result = 0;
  776. if (acpi_disabled) {
  777. printk(KERN_INFO PREFIX "Interpreter disabled.\n");
  778. return -ENODEV;
  779. }
  780. acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
  781. if (!acpi_kobj) {
  782. printk(KERN_WARNING "%s: kset create error\n", __func__);
  783. acpi_kobj = NULL;
  784. }
  785. init_acpi_device_notify();
  786. result = acpi_bus_init();
  787. if (!result) {
  788. pci_mmcfg_late_init();
  789. if (!(pm_flags & PM_APM))
  790. pm_flags |= PM_ACPI;
  791. else {
  792. printk(KERN_INFO PREFIX
  793. "APM is already active, exiting\n");
  794. disable_acpi();
  795. result = -ENODEV;
  796. }
  797. } else
  798. disable_acpi();
  799. if (acpi_disabled)
  800. return result;
  801. /*
  802. * If the laptop falls into the DMI check table, the power state check
  803. * will be disabled in the course of device power transistion.
  804. */
  805. dmi_check_system(power_nocheck_dmi_table);
  806. acpi_scan_init();
  807. acpi_ec_init();
  808. acpi_power_init();
  809. acpi_system_init();
  810. acpi_debug_init();
  811. acpi_sleep_proc_init();
  812. acpi_wakeup_device_init();
  813. return result;
  814. }
  815. subsys_initcall(acpi_init);