osl.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /*
  2. * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
  3. *
  4. * Copyright (C) 2000 Andrew Henroid
  5. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  6. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  7. * Copyright (c) 2008 Intel Corporation
  8. * Author: Matthew Wilcox <willy@linux.intel.com>
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. *
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/mm.h>
  33. #include <linux/pci.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/kmod.h>
  36. #include <linux/delay.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/nmi.h>
  39. #include <linux/acpi.h>
  40. #include <linux/efi.h>
  41. #include <linux/ioport.h>
  42. #include <linux/list.h>
  43. #include <linux/jiffies.h>
  44. #include <linux/semaphore.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h>
  47. #include <acpi/acpi.h>
  48. #include <acpi/acpi_bus.h>
  49. #include <acpi/processor.h>
  50. #define _COMPONENT ACPI_OS_SERVICES
  51. ACPI_MODULE_NAME("osl");
  52. #define PREFIX "ACPI: "
  53. struct acpi_os_dpc {
  54. acpi_osd_exec_callback function;
  55. void *context;
  56. struct work_struct work;
  57. };
  58. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  59. #include CONFIG_ACPI_CUSTOM_DSDT_FILE
  60. #endif
  61. #ifdef ENABLE_DEBUGGER
  62. #include <linux/kdb.h>
  63. /* stuff for debugger support */
  64. int acpi_in_debugger;
  65. EXPORT_SYMBOL(acpi_in_debugger);
  66. extern char line_buf[80];
  67. #endif /*ENABLE_DEBUGGER */
  68. static unsigned int acpi_irq_irq;
  69. static acpi_osd_handler acpi_irq_handler;
  70. static void *acpi_irq_context;
  71. static struct workqueue_struct *kacpid_wq;
  72. static struct workqueue_struct *kacpi_notify_wq;
  73. static struct workqueue_struct *kacpi_hotplug_wq;
  74. struct acpi_res_list {
  75. resource_size_t start;
  76. resource_size_t end;
  77. acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
  78. char name[5]; /* only can have a length of 4 chars, make use of this
  79. one instead of res->name, no need to kalloc then */
  80. struct list_head resource_list;
  81. };
  82. static LIST_HEAD(resource_list_head);
  83. static DEFINE_SPINLOCK(acpi_res_lock);
  84. #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
  85. static char osi_additional_string[OSI_STRING_LENGTH_MAX];
  86. /*
  87. * The story of _OSI(Linux)
  88. *
  89. * From pre-history through Linux-2.6.22,
  90. * Linux responded TRUE upon a BIOS OSI(Linux) query.
  91. *
  92. * Unfortunately, reference BIOS writers got wind of this
  93. * and put OSI(Linux) in their example code, quickly exposing
  94. * this string as ill-conceived and opening the door to
  95. * an un-bounded number of BIOS incompatibilities.
  96. *
  97. * For example, OSI(Linux) was used on resume to re-POST a
  98. * video card on one system, because Linux at that time
  99. * could not do a speedy restore in its native driver.
  100. * But then upon gaining quick native restore capability,
  101. * Linux has no way to tell the BIOS to skip the time-consuming
  102. * POST -- putting Linux at a permanent performance disadvantage.
  103. * On another system, the BIOS writer used OSI(Linux)
  104. * to infer native OS support for IPMI! On other systems,
  105. * OSI(Linux) simply got in the way of Linux claiming to
  106. * be compatible with other operating systems, exposing
  107. * BIOS issues such as skipped device initialization.
  108. *
  109. * So "Linux" turned out to be a really poor chose of
  110. * OSI string, and from Linux-2.6.23 onward we respond FALSE.
  111. *
  112. * BIOS writers should NOT query _OSI(Linux) on future systems.
  113. * Linux will complain on the console when it sees it, and return FALSE.
  114. * To get Linux to return TRUE for your system will require
  115. * a kernel source update to add a DMI entry,
  116. * or boot with "acpi_osi=Linux"
  117. */
  118. static struct osi_linux {
  119. unsigned int enable:1;
  120. unsigned int dmi:1;
  121. unsigned int cmdline:1;
  122. unsigned int known:1;
  123. } osi_linux = { 0, 0, 0, 0};
  124. static void __init acpi_request_region (struct acpi_generic_address *addr,
  125. unsigned int length, char *desc)
  126. {
  127. struct resource *res;
  128. if (!addr->address || !length)
  129. return;
  130. if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  131. res = request_region(addr->address, length, desc);
  132. else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
  133. res = request_mem_region(addr->address, length, desc);
  134. }
  135. static int __init acpi_reserve_resources(void)
  136. {
  137. acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
  138. "ACPI PM1a_EVT_BLK");
  139. acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
  140. "ACPI PM1b_EVT_BLK");
  141. acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
  142. "ACPI PM1a_CNT_BLK");
  143. acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
  144. "ACPI PM1b_CNT_BLK");
  145. if (acpi_gbl_FADT.pm_timer_length == 4)
  146. acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
  147. acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
  148. "ACPI PM2_CNT_BLK");
  149. /* Length of GPE blocks must be a non-negative multiple of 2 */
  150. if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
  151. acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
  152. acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
  153. if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
  154. acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
  155. acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
  156. return 0;
  157. }
  158. device_initcall(acpi_reserve_resources);
  159. acpi_status __init acpi_os_initialize(void)
  160. {
  161. return AE_OK;
  162. }
  163. static void bind_to_cpu0(struct work_struct *work)
  164. {
  165. set_cpus_allowed(current, cpumask_of_cpu(0));
  166. kfree(work);
  167. }
  168. static void bind_workqueue(struct workqueue_struct *wq)
  169. {
  170. struct work_struct *work;
  171. work = kzalloc(sizeof(struct work_struct), GFP_KERNEL);
  172. INIT_WORK(work, bind_to_cpu0);
  173. queue_work(wq, work);
  174. }
  175. acpi_status acpi_os_initialize1(void)
  176. {
  177. /*
  178. * On some machines, a software-initiated SMI causes corruption unless
  179. * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
  180. * typically it's done in GPE-related methods that are run via
  181. * workqueues, so we can avoid the known corruption cases by binding
  182. * the workqueues to CPU 0.
  183. */
  184. kacpid_wq = create_singlethread_workqueue("kacpid");
  185. bind_workqueue(kacpid_wq);
  186. kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
  187. bind_workqueue(kacpi_notify_wq);
  188. kacpi_hotplug_wq = create_singlethread_workqueue("kacpi_hotplug");
  189. bind_workqueue(kacpi_hotplug_wq);
  190. BUG_ON(!kacpid_wq);
  191. BUG_ON(!kacpi_notify_wq);
  192. BUG_ON(!kacpi_hotplug_wq);
  193. return AE_OK;
  194. }
  195. acpi_status acpi_os_terminate(void)
  196. {
  197. if (acpi_irq_handler) {
  198. acpi_os_remove_interrupt_handler(acpi_irq_irq,
  199. acpi_irq_handler);
  200. }
  201. destroy_workqueue(kacpid_wq);
  202. destroy_workqueue(kacpi_notify_wq);
  203. destroy_workqueue(kacpi_hotplug_wq);
  204. return AE_OK;
  205. }
  206. void acpi_os_printf(const char *fmt, ...)
  207. {
  208. va_list args;
  209. va_start(args, fmt);
  210. acpi_os_vprintf(fmt, args);
  211. va_end(args);
  212. }
  213. void acpi_os_vprintf(const char *fmt, va_list args)
  214. {
  215. static char buffer[512];
  216. vsprintf(buffer, fmt, args);
  217. #ifdef ENABLE_DEBUGGER
  218. if (acpi_in_debugger) {
  219. kdb_printf("%s", buffer);
  220. } else {
  221. printk(KERN_CONT "%s", buffer);
  222. }
  223. #else
  224. printk(KERN_CONT "%s", buffer);
  225. #endif
  226. }
  227. acpi_physical_address __init acpi_os_get_root_pointer(void)
  228. {
  229. if (efi_enabled) {
  230. if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  231. return efi.acpi20;
  232. else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  233. return efi.acpi;
  234. else {
  235. printk(KERN_ERR PREFIX
  236. "System description tables not found\n");
  237. return 0;
  238. }
  239. } else {
  240. acpi_physical_address pa = 0;
  241. acpi_find_root_pointer(&pa);
  242. return pa;
  243. }
  244. }
  245. void __iomem *__init_refok
  246. acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
  247. {
  248. if (phys > ULONG_MAX) {
  249. printk(KERN_ERR PREFIX "Cannot map memory that high\n");
  250. return NULL;
  251. }
  252. if (acpi_gbl_permanent_mmap)
  253. /*
  254. * ioremap checks to ensure this is in reserved space
  255. */
  256. return ioremap((unsigned long)phys, size);
  257. else
  258. return __acpi_map_table((unsigned long)phys, size);
  259. }
  260. EXPORT_SYMBOL_GPL(acpi_os_map_memory);
  261. void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  262. {
  263. if (acpi_gbl_permanent_mmap)
  264. iounmap(virt);
  265. else
  266. __acpi_unmap_table(virt, size);
  267. }
  268. EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
  269. void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  270. {
  271. if (!acpi_gbl_permanent_mmap)
  272. __acpi_unmap_table(virt, size);
  273. }
  274. #ifdef ACPI_FUTURE_USAGE
  275. acpi_status
  276. acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
  277. {
  278. if (!phys || !virt)
  279. return AE_BAD_PARAMETER;
  280. *phys = virt_to_phys(virt);
  281. return AE_OK;
  282. }
  283. #endif
  284. #define ACPI_MAX_OVERRIDE_LEN 100
  285. static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
  286. acpi_status
  287. acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
  288. acpi_string * new_val)
  289. {
  290. if (!init_val || !new_val)
  291. return AE_BAD_PARAMETER;
  292. *new_val = NULL;
  293. if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
  294. printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
  295. acpi_os_name);
  296. *new_val = acpi_os_name;
  297. }
  298. return AE_OK;
  299. }
  300. acpi_status
  301. acpi_os_table_override(struct acpi_table_header * existing_table,
  302. struct acpi_table_header ** new_table)
  303. {
  304. if (!existing_table || !new_table)
  305. return AE_BAD_PARAMETER;
  306. *new_table = NULL;
  307. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  308. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  309. *new_table = (struct acpi_table_header *)AmlCode;
  310. #endif
  311. if (*new_table != NULL) {
  312. printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
  313. "this is unsafe: tainting kernel\n",
  314. existing_table->signature,
  315. existing_table->oem_table_id);
  316. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  317. }
  318. return AE_OK;
  319. }
  320. static irqreturn_t acpi_irq(int irq, void *dev_id)
  321. {
  322. u32 handled;
  323. handled = (*acpi_irq_handler) (acpi_irq_context);
  324. if (handled) {
  325. acpi_irq_handled++;
  326. return IRQ_HANDLED;
  327. } else {
  328. acpi_irq_not_handled++;
  329. return IRQ_NONE;
  330. }
  331. }
  332. acpi_status
  333. acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
  334. void *context)
  335. {
  336. unsigned int irq;
  337. acpi_irq_stats_init();
  338. /*
  339. * Ignore the GSI from the core, and use the value in our copy of the
  340. * FADT. It may not be the same if an interrupt source override exists
  341. * for the SCI.
  342. */
  343. gsi = acpi_gbl_FADT.sci_interrupt;
  344. if (acpi_gsi_to_irq(gsi, &irq) < 0) {
  345. printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
  346. gsi);
  347. return AE_OK;
  348. }
  349. acpi_irq_handler = handler;
  350. acpi_irq_context = context;
  351. if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
  352. printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
  353. return AE_NOT_ACQUIRED;
  354. }
  355. acpi_irq_irq = irq;
  356. return AE_OK;
  357. }
  358. acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
  359. {
  360. if (irq) {
  361. free_irq(irq, acpi_irq);
  362. acpi_irq_handler = NULL;
  363. acpi_irq_irq = 0;
  364. }
  365. return AE_OK;
  366. }
  367. /*
  368. * Running in interpreter thread context, safe to sleep
  369. */
  370. void acpi_os_sleep(acpi_integer ms)
  371. {
  372. schedule_timeout_interruptible(msecs_to_jiffies(ms));
  373. }
  374. void acpi_os_stall(u32 us)
  375. {
  376. while (us) {
  377. u32 delay = 1000;
  378. if (delay > us)
  379. delay = us;
  380. udelay(delay);
  381. touch_nmi_watchdog();
  382. us -= delay;
  383. }
  384. }
  385. /*
  386. * Support ACPI 3.0 AML Timer operand
  387. * Returns 64-bit free-running, monotonically increasing timer
  388. * with 100ns granularity
  389. */
  390. u64 acpi_os_get_timer(void)
  391. {
  392. static u64 t;
  393. #ifdef CONFIG_HPET
  394. /* TBD: use HPET if available */
  395. #endif
  396. #ifdef CONFIG_X86_PM_TIMER
  397. /* TBD: default to PM timer if HPET was not available */
  398. #endif
  399. if (!t)
  400. printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
  401. return ++t;
  402. }
  403. acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  404. {
  405. u32 dummy;
  406. if (!value)
  407. value = &dummy;
  408. *value = 0;
  409. if (width <= 8) {
  410. *(u8 *) value = inb(port);
  411. } else if (width <= 16) {
  412. *(u16 *) value = inw(port);
  413. } else if (width <= 32) {
  414. *(u32 *) value = inl(port);
  415. } else {
  416. BUG();
  417. }
  418. return AE_OK;
  419. }
  420. EXPORT_SYMBOL(acpi_os_read_port);
  421. acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  422. {
  423. if (width <= 8) {
  424. outb(value, port);
  425. } else if (width <= 16) {
  426. outw(value, port);
  427. } else if (width <= 32) {
  428. outl(value, port);
  429. } else {
  430. BUG();
  431. }
  432. return AE_OK;
  433. }
  434. EXPORT_SYMBOL(acpi_os_write_port);
  435. acpi_status
  436. acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
  437. {
  438. u32 dummy;
  439. void __iomem *virt_addr;
  440. virt_addr = ioremap(phys_addr, width);
  441. if (!value)
  442. value = &dummy;
  443. switch (width) {
  444. case 8:
  445. *(u8 *) value = readb(virt_addr);
  446. break;
  447. case 16:
  448. *(u16 *) value = readw(virt_addr);
  449. break;
  450. case 32:
  451. *(u32 *) value = readl(virt_addr);
  452. break;
  453. default:
  454. BUG();
  455. }
  456. iounmap(virt_addr);
  457. return AE_OK;
  458. }
  459. acpi_status
  460. acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
  461. {
  462. void __iomem *virt_addr;
  463. virt_addr = ioremap(phys_addr, width);
  464. switch (width) {
  465. case 8:
  466. writeb(value, virt_addr);
  467. break;
  468. case 16:
  469. writew(value, virt_addr);
  470. break;
  471. case 32:
  472. writel(value, virt_addr);
  473. break;
  474. default:
  475. BUG();
  476. }
  477. iounmap(virt_addr);
  478. return AE_OK;
  479. }
  480. acpi_status
  481. acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  482. u32 *value, u32 width)
  483. {
  484. int result, size;
  485. if (!value)
  486. return AE_BAD_PARAMETER;
  487. switch (width) {
  488. case 8:
  489. size = 1;
  490. break;
  491. case 16:
  492. size = 2;
  493. break;
  494. case 32:
  495. size = 4;
  496. break;
  497. default:
  498. return AE_ERROR;
  499. }
  500. result = raw_pci_read(pci_id->segment, pci_id->bus,
  501. PCI_DEVFN(pci_id->device, pci_id->function),
  502. reg, size, value);
  503. return (result ? AE_ERROR : AE_OK);
  504. }
  505. acpi_status
  506. acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  507. acpi_integer value, u32 width)
  508. {
  509. int result, size;
  510. switch (width) {
  511. case 8:
  512. size = 1;
  513. break;
  514. case 16:
  515. size = 2;
  516. break;
  517. case 32:
  518. size = 4;
  519. break;
  520. default:
  521. return AE_ERROR;
  522. }
  523. result = raw_pci_write(pci_id->segment, pci_id->bus,
  524. PCI_DEVFN(pci_id->device, pci_id->function),
  525. reg, size, value);
  526. return (result ? AE_ERROR : AE_OK);
  527. }
  528. /* TODO: Change code to take advantage of driver model more */
  529. static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
  530. acpi_handle chandle, /* current node */
  531. struct acpi_pci_id **id,
  532. int *is_bridge, u8 * bus_number)
  533. {
  534. acpi_handle handle;
  535. struct acpi_pci_id *pci_id = *id;
  536. acpi_status status;
  537. unsigned long long temp;
  538. acpi_object_type type;
  539. acpi_get_parent(chandle, &handle);
  540. if (handle != rhandle) {
  541. acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
  542. bus_number);
  543. status = acpi_get_type(handle, &type);
  544. if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
  545. return;
  546. status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
  547. &temp);
  548. if (ACPI_SUCCESS(status)) {
  549. u32 val;
  550. pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
  551. pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
  552. if (*is_bridge)
  553. pci_id->bus = *bus_number;
  554. /* any nicer way to get bus number of bridge ? */
  555. status =
  556. acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
  557. 8);
  558. if (ACPI_SUCCESS(status)
  559. && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
  560. status =
  561. acpi_os_read_pci_configuration(pci_id, 0x18,
  562. &val, 8);
  563. if (!ACPI_SUCCESS(status)) {
  564. /* Certainly broken... FIX ME */
  565. return;
  566. }
  567. *is_bridge = 1;
  568. pci_id->bus = val;
  569. status =
  570. acpi_os_read_pci_configuration(pci_id, 0x19,
  571. &val, 8);
  572. if (ACPI_SUCCESS(status)) {
  573. *bus_number = val;
  574. }
  575. } else
  576. *is_bridge = 0;
  577. }
  578. }
  579. }
  580. void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
  581. acpi_handle chandle, /* current node */
  582. struct acpi_pci_id **id)
  583. {
  584. int is_bridge = 1;
  585. u8 bus_number = (*id)->bus;
  586. acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
  587. }
  588. static void acpi_os_execute_deferred(struct work_struct *work)
  589. {
  590. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  591. if (!dpc) {
  592. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  593. return;
  594. }
  595. dpc->function(dpc->context);
  596. kfree(dpc);
  597. return;
  598. }
  599. static void acpi_os_execute_hp_deferred(struct work_struct *work)
  600. {
  601. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  602. if (!dpc) {
  603. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  604. return;
  605. }
  606. acpi_os_wait_events_complete(NULL);
  607. dpc->function(dpc->context);
  608. kfree(dpc);
  609. return;
  610. }
  611. /*******************************************************************************
  612. *
  613. * FUNCTION: acpi_os_execute
  614. *
  615. * PARAMETERS: Type - Type of the callback
  616. * Function - Function to be executed
  617. * Context - Function parameters
  618. *
  619. * RETURN: Status
  620. *
  621. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  622. * immediately executes function on a separate thread.
  623. *
  624. ******************************************************************************/
  625. static acpi_status __acpi_os_execute(acpi_execute_type type,
  626. acpi_osd_exec_callback function, void *context, int hp)
  627. {
  628. acpi_status status = AE_OK;
  629. struct acpi_os_dpc *dpc;
  630. struct workqueue_struct *queue;
  631. work_func_t func;
  632. int ret;
  633. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  634. "Scheduling function [%p(%p)] for deferred execution.\n",
  635. function, context));
  636. if (!function)
  637. return AE_BAD_PARAMETER;
  638. /*
  639. * Allocate/initialize DPC structure. Note that this memory will be
  640. * freed by the callee. The kernel handles the work_struct list in a
  641. * way that allows us to also free its memory inside the callee.
  642. * Because we may want to schedule several tasks with different
  643. * parameters we can't use the approach some kernel code uses of
  644. * having a static work_struct.
  645. */
  646. dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  647. if (!dpc)
  648. return AE_NO_MEMORY;
  649. dpc->function = function;
  650. dpc->context = context;
  651. /*
  652. * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
  653. * because the hotplug code may call driver .remove() functions,
  654. * which invoke flush_scheduled_work/acpi_os_wait_events_complete
  655. * to flush these workqueues.
  656. */
  657. queue = hp ? kacpi_hotplug_wq :
  658. (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
  659. func = hp ? acpi_os_execute_hp_deferred : acpi_os_execute_deferred;
  660. INIT_WORK(&dpc->work, func);
  661. ret = queue_work(queue, &dpc->work);
  662. if (!ret) {
  663. printk(KERN_ERR PREFIX
  664. "Call to queue_work() failed.\n");
  665. status = AE_ERROR;
  666. kfree(dpc);
  667. }
  668. return status;
  669. }
  670. acpi_status acpi_os_execute(acpi_execute_type type,
  671. acpi_osd_exec_callback function, void *context)
  672. {
  673. return __acpi_os_execute(type, function, context, 0);
  674. }
  675. EXPORT_SYMBOL(acpi_os_execute);
  676. acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
  677. void *context)
  678. {
  679. return __acpi_os_execute(0, function, context, 1);
  680. }
  681. void acpi_os_wait_events_complete(void *context)
  682. {
  683. flush_workqueue(kacpid_wq);
  684. flush_workqueue(kacpi_notify_wq);
  685. }
  686. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  687. /*
  688. * Allocate the memory for a spinlock and initialize it.
  689. */
  690. acpi_status acpi_os_create_lock(acpi_spinlock * handle)
  691. {
  692. spin_lock_init(*handle);
  693. return AE_OK;
  694. }
  695. /*
  696. * Deallocate the memory for a spinlock.
  697. */
  698. void acpi_os_delete_lock(acpi_spinlock handle)
  699. {
  700. return;
  701. }
  702. acpi_status
  703. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  704. {
  705. struct semaphore *sem = NULL;
  706. sem = acpi_os_allocate(sizeof(struct semaphore));
  707. if (!sem)
  708. return AE_NO_MEMORY;
  709. memset(sem, 0, sizeof(struct semaphore));
  710. sema_init(sem, initial_units);
  711. *handle = (acpi_handle *) sem;
  712. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  713. *handle, initial_units));
  714. return AE_OK;
  715. }
  716. /*
  717. * TODO: A better way to delete semaphores? Linux doesn't have a
  718. * 'delete_semaphore()' function -- may result in an invalid
  719. * pointer dereference for non-synchronized consumers. Should
  720. * we at least check for blocked threads and signal/cancel them?
  721. */
  722. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  723. {
  724. struct semaphore *sem = (struct semaphore *)handle;
  725. if (!sem)
  726. return AE_BAD_PARAMETER;
  727. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  728. BUG_ON(!list_empty(&sem->wait_list));
  729. kfree(sem);
  730. sem = NULL;
  731. return AE_OK;
  732. }
  733. /*
  734. * TODO: Support for units > 1?
  735. */
  736. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  737. {
  738. acpi_status status = AE_OK;
  739. struct semaphore *sem = (struct semaphore *)handle;
  740. long jiffies;
  741. int ret = 0;
  742. if (!sem || (units < 1))
  743. return AE_BAD_PARAMETER;
  744. if (units > 1)
  745. return AE_SUPPORT;
  746. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  747. handle, units, timeout));
  748. if (timeout == ACPI_WAIT_FOREVER)
  749. jiffies = MAX_SCHEDULE_TIMEOUT;
  750. else
  751. jiffies = msecs_to_jiffies(timeout);
  752. ret = down_timeout(sem, jiffies);
  753. if (ret)
  754. status = AE_TIME;
  755. if (ACPI_FAILURE(status)) {
  756. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  757. "Failed to acquire semaphore[%p|%d|%d], %s",
  758. handle, units, timeout,
  759. acpi_format_exception(status)));
  760. } else {
  761. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  762. "Acquired semaphore[%p|%d|%d]", handle,
  763. units, timeout));
  764. }
  765. return status;
  766. }
  767. /*
  768. * TODO: Support for units > 1?
  769. */
  770. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  771. {
  772. struct semaphore *sem = (struct semaphore *)handle;
  773. if (!sem || (units < 1))
  774. return AE_BAD_PARAMETER;
  775. if (units > 1)
  776. return AE_SUPPORT;
  777. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  778. units));
  779. up(sem);
  780. return AE_OK;
  781. }
  782. #ifdef ACPI_FUTURE_USAGE
  783. u32 acpi_os_get_line(char *buffer)
  784. {
  785. #ifdef ENABLE_DEBUGGER
  786. if (acpi_in_debugger) {
  787. u32 chars;
  788. kdb_read(buffer, sizeof(line_buf));
  789. /* remove the CR kdb includes */
  790. chars = strlen(buffer) - 1;
  791. buffer[chars] = '\0';
  792. }
  793. #endif
  794. return 0;
  795. }
  796. #endif /* ACPI_FUTURE_USAGE */
  797. acpi_status acpi_os_signal(u32 function, void *info)
  798. {
  799. switch (function) {
  800. case ACPI_SIGNAL_FATAL:
  801. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  802. break;
  803. case ACPI_SIGNAL_BREAKPOINT:
  804. /*
  805. * AML Breakpoint
  806. * ACPI spec. says to treat it as a NOP unless
  807. * you are debugging. So if/when we integrate
  808. * AML debugger into the kernel debugger its
  809. * hook will go here. But until then it is
  810. * not useful to print anything on breakpoints.
  811. */
  812. break;
  813. default:
  814. break;
  815. }
  816. return AE_OK;
  817. }
  818. static int __init acpi_os_name_setup(char *str)
  819. {
  820. char *p = acpi_os_name;
  821. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  822. if (!str || !*str)
  823. return 0;
  824. for (; count-- && str && *str; str++) {
  825. if (isalnum(*str) || *str == ' ' || *str == ':')
  826. *p++ = *str;
  827. else if (*str == '\'' || *str == '"')
  828. continue;
  829. else
  830. break;
  831. }
  832. *p = 0;
  833. return 1;
  834. }
  835. __setup("acpi_os_name=", acpi_os_name_setup);
  836. static void __init set_osi_linux(unsigned int enable)
  837. {
  838. if (osi_linux.enable != enable) {
  839. osi_linux.enable = enable;
  840. printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
  841. enable ? "Add": "Delet");
  842. }
  843. return;
  844. }
  845. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  846. {
  847. osi_linux.cmdline = 1; /* cmdline set the default */
  848. set_osi_linux(enable);
  849. return;
  850. }
  851. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  852. {
  853. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  854. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  855. if (enable == -1)
  856. return;
  857. osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
  858. set_osi_linux(enable);
  859. return;
  860. }
  861. /*
  862. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  863. *
  864. * empty string disables _OSI
  865. * string starting with '!' disables that string
  866. * otherwise string is added to list, augmenting built-in strings
  867. */
  868. int __init acpi_osi_setup(char *str)
  869. {
  870. if (str == NULL || *str == '\0') {
  871. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  872. acpi_gbl_create_osi_method = FALSE;
  873. } else if (!strcmp("!Linux", str)) {
  874. acpi_cmdline_osi_linux(0); /* !enable */
  875. } else if (*str == '!') {
  876. if (acpi_osi_invalidate(++str) == AE_OK)
  877. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  878. } else if (!strcmp("Linux", str)) {
  879. acpi_cmdline_osi_linux(1); /* enable */
  880. } else if (*osi_additional_string == '\0') {
  881. strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
  882. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  883. }
  884. return 1;
  885. }
  886. __setup("acpi_osi=", acpi_osi_setup);
  887. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  888. static int __init acpi_serialize_setup(char *str)
  889. {
  890. printk(KERN_INFO PREFIX "serialize enabled\n");
  891. acpi_gbl_all_methods_serialized = TRUE;
  892. return 1;
  893. }
  894. __setup("acpi_serialize", acpi_serialize_setup);
  895. /*
  896. * Wake and Run-Time GPES are expected to be separate.
  897. * We disable wake-GPEs at run-time to prevent spurious
  898. * interrupts.
  899. *
  900. * However, if a system exists that shares Wake and
  901. * Run-time events on the same GPE this flag is available
  902. * to tell Linux to keep the wake-time GPEs enabled at run-time.
  903. */
  904. static int __init acpi_wake_gpes_always_on_setup(char *str)
  905. {
  906. printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
  907. acpi_gbl_leave_wake_gpes_disabled = FALSE;
  908. return 1;
  909. }
  910. __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
  911. /* Check of resource interference between native drivers and ACPI
  912. * OperationRegions (SystemIO and System Memory only).
  913. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  914. * in arbitrary AML code and can interfere with legacy drivers.
  915. * acpi_enforce_resources= can be set to:
  916. *
  917. * - strict (default) (2)
  918. * -> further driver trying to access the resources will not load
  919. * - lax (1)
  920. * -> further driver trying to access the resources will load, but you
  921. * get a system message that something might go wrong...
  922. *
  923. * - no (0)
  924. * -> ACPI Operation Region resources will not be registered
  925. *
  926. */
  927. #define ENFORCE_RESOURCES_STRICT 2
  928. #define ENFORCE_RESOURCES_LAX 1
  929. #define ENFORCE_RESOURCES_NO 0
  930. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  931. static int __init acpi_enforce_resources_setup(char *str)
  932. {
  933. if (str == NULL || *str == '\0')
  934. return 0;
  935. if (!strcmp("strict", str))
  936. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  937. else if (!strcmp("lax", str))
  938. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  939. else if (!strcmp("no", str))
  940. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  941. return 1;
  942. }
  943. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  944. /* Check for resource conflicts between ACPI OperationRegions and native
  945. * drivers */
  946. int acpi_check_resource_conflict(struct resource *res)
  947. {
  948. struct acpi_res_list *res_list_elem;
  949. int ioport;
  950. int clash = 0;
  951. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  952. return 0;
  953. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  954. return 0;
  955. ioport = res->flags & IORESOURCE_IO;
  956. spin_lock(&acpi_res_lock);
  957. list_for_each_entry(res_list_elem, &resource_list_head,
  958. resource_list) {
  959. if (ioport && (res_list_elem->resource_type
  960. != ACPI_ADR_SPACE_SYSTEM_IO))
  961. continue;
  962. if (!ioport && (res_list_elem->resource_type
  963. != ACPI_ADR_SPACE_SYSTEM_MEMORY))
  964. continue;
  965. if (res->end < res_list_elem->start
  966. || res_list_elem->end < res->start)
  967. continue;
  968. clash = 1;
  969. break;
  970. }
  971. spin_unlock(&acpi_res_lock);
  972. if (clash) {
  973. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  974. printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
  975. " conflicts with ACPI region %s"
  976. " [0x%llx-0x%llx]\n",
  977. acpi_enforce_resources == ENFORCE_RESOURCES_LAX
  978. ? KERN_WARNING : KERN_ERR,
  979. ioport ? "I/O" : "Memory", res->name,
  980. (long long) res->start, (long long) res->end,
  981. res_list_elem->name,
  982. (long long) res_list_elem->start,
  983. (long long) res_list_elem->end);
  984. printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
  985. }
  986. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  987. return -EBUSY;
  988. }
  989. return 0;
  990. }
  991. EXPORT_SYMBOL(acpi_check_resource_conflict);
  992. int acpi_check_region(resource_size_t start, resource_size_t n,
  993. const char *name)
  994. {
  995. struct resource res = {
  996. .start = start,
  997. .end = start + n - 1,
  998. .name = name,
  999. .flags = IORESOURCE_IO,
  1000. };
  1001. return acpi_check_resource_conflict(&res);
  1002. }
  1003. EXPORT_SYMBOL(acpi_check_region);
  1004. int acpi_check_mem_region(resource_size_t start, resource_size_t n,
  1005. const char *name)
  1006. {
  1007. struct resource res = {
  1008. .start = start,
  1009. .end = start + n - 1,
  1010. .name = name,
  1011. .flags = IORESOURCE_MEM,
  1012. };
  1013. return acpi_check_resource_conflict(&res);
  1014. }
  1015. EXPORT_SYMBOL(acpi_check_mem_region);
  1016. /*
  1017. * Acquire a spinlock.
  1018. *
  1019. * handle is a pointer to the spinlock_t.
  1020. */
  1021. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1022. {
  1023. acpi_cpu_flags flags;
  1024. spin_lock_irqsave(lockp, flags);
  1025. return flags;
  1026. }
  1027. /*
  1028. * Release a spinlock. See above.
  1029. */
  1030. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1031. {
  1032. spin_unlock_irqrestore(lockp, flags);
  1033. }
  1034. #ifndef ACPI_USE_LOCAL_CACHE
  1035. /*******************************************************************************
  1036. *
  1037. * FUNCTION: acpi_os_create_cache
  1038. *
  1039. * PARAMETERS: name - Ascii name for the cache
  1040. * size - Size of each cached object
  1041. * depth - Maximum depth of the cache (in objects) <ignored>
  1042. * cache - Where the new cache object is returned
  1043. *
  1044. * RETURN: status
  1045. *
  1046. * DESCRIPTION: Create a cache object
  1047. *
  1048. ******************************************************************************/
  1049. acpi_status
  1050. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1051. {
  1052. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1053. if (*cache == NULL)
  1054. return AE_ERROR;
  1055. else
  1056. return AE_OK;
  1057. }
  1058. /*******************************************************************************
  1059. *
  1060. * FUNCTION: acpi_os_purge_cache
  1061. *
  1062. * PARAMETERS: Cache - Handle to cache object
  1063. *
  1064. * RETURN: Status
  1065. *
  1066. * DESCRIPTION: Free all objects within the requested cache.
  1067. *
  1068. ******************************************************************************/
  1069. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1070. {
  1071. kmem_cache_shrink(cache);
  1072. return (AE_OK);
  1073. }
  1074. /*******************************************************************************
  1075. *
  1076. * FUNCTION: acpi_os_delete_cache
  1077. *
  1078. * PARAMETERS: Cache - Handle to cache object
  1079. *
  1080. * RETURN: Status
  1081. *
  1082. * DESCRIPTION: Free all objects within the requested cache and delete the
  1083. * cache object.
  1084. *
  1085. ******************************************************************************/
  1086. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1087. {
  1088. kmem_cache_destroy(cache);
  1089. return (AE_OK);
  1090. }
  1091. /*******************************************************************************
  1092. *
  1093. * FUNCTION: acpi_os_release_object
  1094. *
  1095. * PARAMETERS: Cache - Handle to cache object
  1096. * Object - The object to be released
  1097. *
  1098. * RETURN: None
  1099. *
  1100. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1101. * the object is deleted.
  1102. *
  1103. ******************************************************************************/
  1104. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1105. {
  1106. kmem_cache_free(cache, object);
  1107. return (AE_OK);
  1108. }
  1109. /******************************************************************************
  1110. *
  1111. * FUNCTION: acpi_os_validate_interface
  1112. *
  1113. * PARAMETERS: interface - Requested interface to be validated
  1114. *
  1115. * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
  1116. *
  1117. * DESCRIPTION: Match an interface string to the interfaces supported by the
  1118. * host. Strings originate from an AML call to the _OSI method.
  1119. *
  1120. *****************************************************************************/
  1121. acpi_status
  1122. acpi_os_validate_interface (char *interface)
  1123. {
  1124. if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
  1125. return AE_OK;
  1126. if (!strcmp("Linux", interface)) {
  1127. printk(KERN_NOTICE PREFIX
  1128. "BIOS _OSI(Linux) query %s%s\n",
  1129. osi_linux.enable ? "honored" : "ignored",
  1130. osi_linux.cmdline ? " via cmdline" :
  1131. osi_linux.dmi ? " via DMI" : "");
  1132. if (osi_linux.enable)
  1133. return AE_OK;
  1134. }
  1135. return AE_SUPPORT;
  1136. }
  1137. /******************************************************************************
  1138. *
  1139. * FUNCTION: acpi_os_validate_address
  1140. *
  1141. * PARAMETERS: space_id - ACPI space ID
  1142. * address - Physical address
  1143. * length - Address length
  1144. *
  1145. * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
  1146. * should return AE_AML_ILLEGAL_ADDRESS.
  1147. *
  1148. * DESCRIPTION: Validate a system address via the host OS. Used to validate
  1149. * the addresses accessed by AML operation regions.
  1150. *
  1151. *****************************************************************************/
  1152. acpi_status
  1153. acpi_os_validate_address (
  1154. u8 space_id,
  1155. acpi_physical_address address,
  1156. acpi_size length,
  1157. char *name)
  1158. {
  1159. struct acpi_res_list *res;
  1160. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1161. return AE_OK;
  1162. switch (space_id) {
  1163. case ACPI_ADR_SPACE_SYSTEM_IO:
  1164. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1165. /* Only interference checks against SystemIO and SytemMemory
  1166. are needed */
  1167. res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
  1168. if (!res)
  1169. return AE_OK;
  1170. /* ACPI names are fixed to 4 bytes, still better use strlcpy */
  1171. strlcpy(res->name, name, 5);
  1172. res->start = address;
  1173. res->end = address + length - 1;
  1174. res->resource_type = space_id;
  1175. spin_lock(&acpi_res_lock);
  1176. list_add(&res->resource_list, &resource_list_head);
  1177. spin_unlock(&acpi_res_lock);
  1178. pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
  1179. "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  1180. ? "SystemIO" : "System Memory",
  1181. (unsigned long long)res->start,
  1182. (unsigned long long)res->end,
  1183. res->name);
  1184. break;
  1185. case ACPI_ADR_SPACE_PCI_CONFIG:
  1186. case ACPI_ADR_SPACE_EC:
  1187. case ACPI_ADR_SPACE_SMBUS:
  1188. case ACPI_ADR_SPACE_CMOS:
  1189. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1190. case ACPI_ADR_SPACE_DATA_TABLE:
  1191. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1192. break;
  1193. }
  1194. return AE_OK;
  1195. }
  1196. #endif