bus.c 25 KB

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