osl.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  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/highmem.h>
  34. #include <linux/pci.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/kmod.h>
  37. #include <linux/delay.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/nmi.h>
  40. #include <linux/acpi.h>
  41. #include <linux/acpi_io.h>
  42. #include <linux/efi.h>
  43. #include <linux/ioport.h>
  44. #include <linux/list.h>
  45. #include <linux/jiffies.h>
  46. #include <linux/semaphore.h>
  47. #include <asm/io.h>
  48. #include <asm/uaccess.h>
  49. #include <acpi/acpi.h>
  50. #include <acpi/acpi_bus.h>
  51. #include <acpi/processor.h>
  52. #define _COMPONENT ACPI_OS_SERVICES
  53. ACPI_MODULE_NAME("osl");
  54. #define PREFIX "ACPI: "
  55. struct acpi_os_dpc {
  56. acpi_osd_exec_callback function;
  57. void *context;
  58. struct work_struct work;
  59. int wait;
  60. };
  61. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  62. #include CONFIG_ACPI_CUSTOM_DSDT_FILE
  63. #endif
  64. #ifdef ENABLE_DEBUGGER
  65. #include <linux/kdb.h>
  66. /* stuff for debugger support */
  67. int acpi_in_debugger;
  68. EXPORT_SYMBOL(acpi_in_debugger);
  69. extern char line_buf[80];
  70. #endif /*ENABLE_DEBUGGER */
  71. static int (*__acpi_os_prepare_sleep)(u8 sleep_state, u32 pm1a_ctrl,
  72. u32 pm1b_ctrl);
  73. static acpi_osd_handler acpi_irq_handler;
  74. static void *acpi_irq_context;
  75. static struct workqueue_struct *kacpid_wq;
  76. static struct workqueue_struct *kacpi_notify_wq;
  77. struct workqueue_struct *kacpi_hotplug_wq;
  78. EXPORT_SYMBOL(kacpi_hotplug_wq);
  79. /*
  80. * This list of permanent mappings is for memory that may be accessed from
  81. * interrupt context, where we can't do the ioremap().
  82. */
  83. struct acpi_ioremap {
  84. struct list_head list;
  85. void __iomem *virt;
  86. acpi_physical_address phys;
  87. acpi_size size;
  88. unsigned long refcount;
  89. };
  90. static LIST_HEAD(acpi_ioremaps);
  91. static DEFINE_MUTEX(acpi_ioremap_lock);
  92. static void __init acpi_osi_setup_late(void);
  93. /*
  94. * The story of _OSI(Linux)
  95. *
  96. * From pre-history through Linux-2.6.22,
  97. * Linux responded TRUE upon a BIOS OSI(Linux) query.
  98. *
  99. * Unfortunately, reference BIOS writers got wind of this
  100. * and put OSI(Linux) in their example code, quickly exposing
  101. * this string as ill-conceived and opening the door to
  102. * an un-bounded number of BIOS incompatibilities.
  103. *
  104. * For example, OSI(Linux) was used on resume to re-POST a
  105. * video card on one system, because Linux at that time
  106. * could not do a speedy restore in its native driver.
  107. * But then upon gaining quick native restore capability,
  108. * Linux has no way to tell the BIOS to skip the time-consuming
  109. * POST -- putting Linux at a permanent performance disadvantage.
  110. * On another system, the BIOS writer used OSI(Linux)
  111. * to infer native OS support for IPMI! On other systems,
  112. * OSI(Linux) simply got in the way of Linux claiming to
  113. * be compatible with other operating systems, exposing
  114. * BIOS issues such as skipped device initialization.
  115. *
  116. * So "Linux" turned out to be a really poor chose of
  117. * OSI string, and from Linux-2.6.23 onward we respond FALSE.
  118. *
  119. * BIOS writers should NOT query _OSI(Linux) on future systems.
  120. * Linux will complain on the console when it sees it, and return FALSE.
  121. * To get Linux to return TRUE for your system will require
  122. * a kernel source update to add a DMI entry,
  123. * or boot with "acpi_osi=Linux"
  124. */
  125. static struct osi_linux {
  126. unsigned int enable:1;
  127. unsigned int dmi:1;
  128. unsigned int cmdline:1;
  129. } osi_linux = {0, 0, 0};
  130. static u32 acpi_osi_handler(acpi_string interface, u32 supported)
  131. {
  132. if (!strcmp("Linux", interface)) {
  133. printk_once(KERN_NOTICE FW_BUG PREFIX
  134. "BIOS _OSI(Linux) query %s%s\n",
  135. osi_linux.enable ? "honored" : "ignored",
  136. osi_linux.cmdline ? " via cmdline" :
  137. osi_linux.dmi ? " via DMI" : "");
  138. }
  139. return supported;
  140. }
  141. static void __init acpi_request_region (struct acpi_generic_address *gas,
  142. unsigned int length, char *desc)
  143. {
  144. u64 addr;
  145. /* Handle possible alignment issues */
  146. memcpy(&addr, &gas->address, sizeof(addr));
  147. if (!addr || !length)
  148. return;
  149. /* Resources are never freed */
  150. if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  151. request_region(addr, length, desc);
  152. else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
  153. request_mem_region(addr, length, desc);
  154. }
  155. static int __init acpi_reserve_resources(void)
  156. {
  157. acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
  158. "ACPI PM1a_EVT_BLK");
  159. acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
  160. "ACPI PM1b_EVT_BLK");
  161. acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
  162. "ACPI PM1a_CNT_BLK");
  163. acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
  164. "ACPI PM1b_CNT_BLK");
  165. if (acpi_gbl_FADT.pm_timer_length == 4)
  166. acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
  167. acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
  168. "ACPI PM2_CNT_BLK");
  169. /* Length of GPE blocks must be a non-negative multiple of 2 */
  170. if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
  171. acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
  172. acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
  173. if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
  174. acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
  175. acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
  176. return 0;
  177. }
  178. device_initcall(acpi_reserve_resources);
  179. void acpi_os_printf(const char *fmt, ...)
  180. {
  181. va_list args;
  182. va_start(args, fmt);
  183. acpi_os_vprintf(fmt, args);
  184. va_end(args);
  185. }
  186. void acpi_os_vprintf(const char *fmt, va_list args)
  187. {
  188. static char buffer[512];
  189. vsprintf(buffer, fmt, args);
  190. #ifdef ENABLE_DEBUGGER
  191. if (acpi_in_debugger) {
  192. kdb_printf("%s", buffer);
  193. } else {
  194. printk(KERN_CONT "%s", buffer);
  195. }
  196. #else
  197. printk(KERN_CONT "%s", buffer);
  198. #endif
  199. }
  200. #ifdef CONFIG_KEXEC
  201. static unsigned long acpi_rsdp;
  202. static int __init setup_acpi_rsdp(char *arg)
  203. {
  204. acpi_rsdp = simple_strtoul(arg, NULL, 16);
  205. return 0;
  206. }
  207. early_param("acpi_rsdp", setup_acpi_rsdp);
  208. #endif
  209. acpi_physical_address __init acpi_os_get_root_pointer(void)
  210. {
  211. #ifdef CONFIG_KEXEC
  212. if (acpi_rsdp)
  213. return acpi_rsdp;
  214. #endif
  215. if (efi_enabled) {
  216. if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  217. return efi.acpi20;
  218. else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  219. return efi.acpi;
  220. else {
  221. printk(KERN_ERR PREFIX
  222. "System description tables not found\n");
  223. return 0;
  224. }
  225. } else {
  226. acpi_physical_address pa = 0;
  227. acpi_find_root_pointer(&pa);
  228. return pa;
  229. }
  230. }
  231. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  232. static struct acpi_ioremap *
  233. acpi_map_lookup(acpi_physical_address phys, acpi_size size)
  234. {
  235. struct acpi_ioremap *map;
  236. list_for_each_entry_rcu(map, &acpi_ioremaps, list)
  237. if (map->phys <= phys &&
  238. phys + size <= map->phys + map->size)
  239. return map;
  240. return NULL;
  241. }
  242. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  243. static void __iomem *
  244. acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size)
  245. {
  246. struct acpi_ioremap *map;
  247. map = acpi_map_lookup(phys, size);
  248. if (map)
  249. return map->virt + (phys - map->phys);
  250. return NULL;
  251. }
  252. void __iomem *acpi_os_get_iomem(acpi_physical_address phys, unsigned int size)
  253. {
  254. struct acpi_ioremap *map;
  255. void __iomem *virt = NULL;
  256. mutex_lock(&acpi_ioremap_lock);
  257. map = acpi_map_lookup(phys, size);
  258. if (map) {
  259. virt = map->virt + (phys - map->phys);
  260. map->refcount++;
  261. }
  262. mutex_unlock(&acpi_ioremap_lock);
  263. return virt;
  264. }
  265. EXPORT_SYMBOL_GPL(acpi_os_get_iomem);
  266. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  267. static struct acpi_ioremap *
  268. acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
  269. {
  270. struct acpi_ioremap *map;
  271. list_for_each_entry_rcu(map, &acpi_ioremaps, list)
  272. if (map->virt <= virt &&
  273. virt + size <= map->virt + map->size)
  274. return map;
  275. return NULL;
  276. }
  277. #ifndef CONFIG_IA64
  278. #define should_use_kmap(pfn) page_is_ram(pfn)
  279. #else
  280. /* ioremap will take care of cache attributes */
  281. #define should_use_kmap(pfn) 0
  282. #endif
  283. static void __iomem *acpi_map(acpi_physical_address pg_off, unsigned long pg_sz)
  284. {
  285. unsigned long pfn;
  286. pfn = pg_off >> PAGE_SHIFT;
  287. if (should_use_kmap(pfn)) {
  288. if (pg_sz > PAGE_SIZE)
  289. return NULL;
  290. return (void __iomem __force *)kmap(pfn_to_page(pfn));
  291. } else
  292. return acpi_os_ioremap(pg_off, pg_sz);
  293. }
  294. static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr)
  295. {
  296. unsigned long pfn;
  297. pfn = pg_off >> PAGE_SHIFT;
  298. if (should_use_kmap(pfn))
  299. kunmap(pfn_to_page(pfn));
  300. else
  301. iounmap(vaddr);
  302. }
  303. void __iomem *__init_refok
  304. acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
  305. {
  306. struct acpi_ioremap *map;
  307. void __iomem *virt;
  308. acpi_physical_address pg_off;
  309. acpi_size pg_sz;
  310. if (phys > ULONG_MAX) {
  311. printk(KERN_ERR PREFIX "Cannot map memory that high\n");
  312. return NULL;
  313. }
  314. if (!acpi_gbl_permanent_mmap)
  315. return __acpi_map_table((unsigned long)phys, size);
  316. mutex_lock(&acpi_ioremap_lock);
  317. /* Check if there's a suitable mapping already. */
  318. map = acpi_map_lookup(phys, size);
  319. if (map) {
  320. map->refcount++;
  321. goto out;
  322. }
  323. map = kzalloc(sizeof(*map), GFP_KERNEL);
  324. if (!map) {
  325. mutex_unlock(&acpi_ioremap_lock);
  326. return NULL;
  327. }
  328. pg_off = round_down(phys, PAGE_SIZE);
  329. pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
  330. virt = acpi_map(pg_off, pg_sz);
  331. if (!virt) {
  332. mutex_unlock(&acpi_ioremap_lock);
  333. kfree(map);
  334. return NULL;
  335. }
  336. INIT_LIST_HEAD(&map->list);
  337. map->virt = virt;
  338. map->phys = pg_off;
  339. map->size = pg_sz;
  340. map->refcount = 1;
  341. list_add_tail_rcu(&map->list, &acpi_ioremaps);
  342. out:
  343. mutex_unlock(&acpi_ioremap_lock);
  344. return map->virt + (phys - map->phys);
  345. }
  346. EXPORT_SYMBOL_GPL(acpi_os_map_memory);
  347. static void acpi_os_drop_map_ref(struct acpi_ioremap *map)
  348. {
  349. if (!--map->refcount)
  350. list_del_rcu(&map->list);
  351. }
  352. static void acpi_os_map_cleanup(struct acpi_ioremap *map)
  353. {
  354. if (!map->refcount) {
  355. synchronize_rcu();
  356. acpi_unmap(map->phys, map->virt);
  357. kfree(map);
  358. }
  359. }
  360. void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  361. {
  362. struct acpi_ioremap *map;
  363. if (!acpi_gbl_permanent_mmap) {
  364. __acpi_unmap_table(virt, size);
  365. return;
  366. }
  367. mutex_lock(&acpi_ioremap_lock);
  368. map = acpi_map_lookup_virt(virt, size);
  369. if (!map) {
  370. mutex_unlock(&acpi_ioremap_lock);
  371. WARN(true, PREFIX "%s: bad address %p\n", __func__, virt);
  372. return;
  373. }
  374. acpi_os_drop_map_ref(map);
  375. mutex_unlock(&acpi_ioremap_lock);
  376. acpi_os_map_cleanup(map);
  377. }
  378. EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
  379. void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  380. {
  381. if (!acpi_gbl_permanent_mmap)
  382. __acpi_unmap_table(virt, size);
  383. }
  384. int acpi_os_map_generic_address(struct acpi_generic_address *gas)
  385. {
  386. u64 addr;
  387. void __iomem *virt;
  388. if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
  389. return 0;
  390. /* Handle possible alignment issues */
  391. memcpy(&addr, &gas->address, sizeof(addr));
  392. if (!addr || !gas->bit_width)
  393. return -EINVAL;
  394. virt = acpi_os_map_memory(addr, gas->bit_width / 8);
  395. if (!virt)
  396. return -EIO;
  397. return 0;
  398. }
  399. EXPORT_SYMBOL(acpi_os_map_generic_address);
  400. void acpi_os_unmap_generic_address(struct acpi_generic_address *gas)
  401. {
  402. u64 addr;
  403. struct acpi_ioremap *map;
  404. if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
  405. return;
  406. /* Handle possible alignment issues */
  407. memcpy(&addr, &gas->address, sizeof(addr));
  408. if (!addr || !gas->bit_width)
  409. return;
  410. mutex_lock(&acpi_ioremap_lock);
  411. map = acpi_map_lookup(addr, gas->bit_width / 8);
  412. if (!map) {
  413. mutex_unlock(&acpi_ioremap_lock);
  414. return;
  415. }
  416. acpi_os_drop_map_ref(map);
  417. mutex_unlock(&acpi_ioremap_lock);
  418. acpi_os_map_cleanup(map);
  419. }
  420. EXPORT_SYMBOL(acpi_os_unmap_generic_address);
  421. #ifdef ACPI_FUTURE_USAGE
  422. acpi_status
  423. acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
  424. {
  425. if (!phys || !virt)
  426. return AE_BAD_PARAMETER;
  427. *phys = virt_to_phys(virt);
  428. return AE_OK;
  429. }
  430. #endif
  431. #define ACPI_MAX_OVERRIDE_LEN 100
  432. static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
  433. acpi_status
  434. acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
  435. acpi_string * new_val)
  436. {
  437. if (!init_val || !new_val)
  438. return AE_BAD_PARAMETER;
  439. *new_val = NULL;
  440. if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
  441. printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
  442. acpi_os_name);
  443. *new_val = acpi_os_name;
  444. }
  445. return AE_OK;
  446. }
  447. acpi_status
  448. acpi_os_table_override(struct acpi_table_header * existing_table,
  449. struct acpi_table_header ** new_table)
  450. {
  451. if (!existing_table || !new_table)
  452. return AE_BAD_PARAMETER;
  453. *new_table = NULL;
  454. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  455. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  456. *new_table = (struct acpi_table_header *)AmlCode;
  457. #endif
  458. if (*new_table != NULL) {
  459. printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
  460. "this is unsafe: tainting kernel\n",
  461. existing_table->signature,
  462. existing_table->oem_table_id);
  463. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  464. }
  465. return AE_OK;
  466. }
  467. acpi_status
  468. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  469. acpi_physical_address * new_address,
  470. u32 *new_table_length)
  471. {
  472. return AE_SUPPORT;
  473. }
  474. static irqreturn_t acpi_irq(int irq, void *dev_id)
  475. {
  476. u32 handled;
  477. handled = (*acpi_irq_handler) (acpi_irq_context);
  478. if (handled) {
  479. acpi_irq_handled++;
  480. return IRQ_HANDLED;
  481. } else {
  482. acpi_irq_not_handled++;
  483. return IRQ_NONE;
  484. }
  485. }
  486. acpi_status
  487. acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
  488. void *context)
  489. {
  490. unsigned int irq;
  491. acpi_irq_stats_init();
  492. /*
  493. * ACPI interrupts different from the SCI in our copy of the FADT are
  494. * not supported.
  495. */
  496. if (gsi != acpi_gbl_FADT.sci_interrupt)
  497. return AE_BAD_PARAMETER;
  498. if (acpi_irq_handler)
  499. return AE_ALREADY_ACQUIRED;
  500. if (acpi_gsi_to_irq(gsi, &irq) < 0) {
  501. printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
  502. gsi);
  503. return AE_OK;
  504. }
  505. acpi_irq_handler = handler;
  506. acpi_irq_context = context;
  507. if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
  508. printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
  509. acpi_irq_handler = NULL;
  510. return AE_NOT_ACQUIRED;
  511. }
  512. return AE_OK;
  513. }
  514. acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
  515. {
  516. if (irq != acpi_gbl_FADT.sci_interrupt)
  517. return AE_BAD_PARAMETER;
  518. free_irq(irq, acpi_irq);
  519. acpi_irq_handler = NULL;
  520. return AE_OK;
  521. }
  522. /*
  523. * Running in interpreter thread context, safe to sleep
  524. */
  525. void acpi_os_sleep(u64 ms)
  526. {
  527. schedule_timeout_interruptible(msecs_to_jiffies(ms));
  528. }
  529. void acpi_os_stall(u32 us)
  530. {
  531. while (us) {
  532. u32 delay = 1000;
  533. if (delay > us)
  534. delay = us;
  535. udelay(delay);
  536. touch_nmi_watchdog();
  537. us -= delay;
  538. }
  539. }
  540. /*
  541. * Support ACPI 3.0 AML Timer operand
  542. * Returns 64-bit free-running, monotonically increasing timer
  543. * with 100ns granularity
  544. */
  545. u64 acpi_os_get_timer(void)
  546. {
  547. static u64 t;
  548. #ifdef CONFIG_HPET
  549. /* TBD: use HPET if available */
  550. #endif
  551. #ifdef CONFIG_X86_PM_TIMER
  552. /* TBD: default to PM timer if HPET was not available */
  553. #endif
  554. if (!t)
  555. printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
  556. return ++t;
  557. }
  558. acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  559. {
  560. u32 dummy;
  561. if (!value)
  562. value = &dummy;
  563. *value = 0;
  564. if (width <= 8) {
  565. *(u8 *) value = inb(port);
  566. } else if (width <= 16) {
  567. *(u16 *) value = inw(port);
  568. } else if (width <= 32) {
  569. *(u32 *) value = inl(port);
  570. } else {
  571. BUG();
  572. }
  573. return AE_OK;
  574. }
  575. EXPORT_SYMBOL(acpi_os_read_port);
  576. acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  577. {
  578. if (width <= 8) {
  579. outb(value, port);
  580. } else if (width <= 16) {
  581. outw(value, port);
  582. } else if (width <= 32) {
  583. outl(value, port);
  584. } else {
  585. BUG();
  586. }
  587. return AE_OK;
  588. }
  589. EXPORT_SYMBOL(acpi_os_write_port);
  590. #ifdef readq
  591. static inline u64 read64(const volatile void __iomem *addr)
  592. {
  593. return readq(addr);
  594. }
  595. #else
  596. static inline u64 read64(const volatile void __iomem *addr)
  597. {
  598. u64 l, h;
  599. l = readl(addr);
  600. h = readl(addr+4);
  601. return l | (h << 32);
  602. }
  603. #endif
  604. acpi_status
  605. acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
  606. {
  607. void __iomem *virt_addr;
  608. unsigned int size = width / 8;
  609. bool unmap = false;
  610. u64 dummy;
  611. rcu_read_lock();
  612. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  613. if (!virt_addr) {
  614. rcu_read_unlock();
  615. virt_addr = acpi_os_ioremap(phys_addr, size);
  616. if (!virt_addr)
  617. return AE_BAD_ADDRESS;
  618. unmap = true;
  619. }
  620. if (!value)
  621. value = &dummy;
  622. switch (width) {
  623. case 8:
  624. *(u8 *) value = readb(virt_addr);
  625. break;
  626. case 16:
  627. *(u16 *) value = readw(virt_addr);
  628. break;
  629. case 32:
  630. *(u32 *) value = readl(virt_addr);
  631. break;
  632. case 64:
  633. *(u64 *) value = read64(virt_addr);
  634. break;
  635. default:
  636. BUG();
  637. }
  638. if (unmap)
  639. iounmap(virt_addr);
  640. else
  641. rcu_read_unlock();
  642. return AE_OK;
  643. }
  644. #ifdef writeq
  645. static inline void write64(u64 val, volatile void __iomem *addr)
  646. {
  647. writeq(val, addr);
  648. }
  649. #else
  650. static inline void write64(u64 val, volatile void __iomem *addr)
  651. {
  652. writel(val, addr);
  653. writel(val>>32, addr+4);
  654. }
  655. #endif
  656. acpi_status
  657. acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
  658. {
  659. void __iomem *virt_addr;
  660. unsigned int size = width / 8;
  661. bool unmap = false;
  662. rcu_read_lock();
  663. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  664. if (!virt_addr) {
  665. rcu_read_unlock();
  666. virt_addr = acpi_os_ioremap(phys_addr, size);
  667. if (!virt_addr)
  668. return AE_BAD_ADDRESS;
  669. unmap = true;
  670. }
  671. switch (width) {
  672. case 8:
  673. writeb(value, virt_addr);
  674. break;
  675. case 16:
  676. writew(value, virt_addr);
  677. break;
  678. case 32:
  679. writel(value, virt_addr);
  680. break;
  681. case 64:
  682. write64(value, virt_addr);
  683. break;
  684. default:
  685. BUG();
  686. }
  687. if (unmap)
  688. iounmap(virt_addr);
  689. else
  690. rcu_read_unlock();
  691. return AE_OK;
  692. }
  693. acpi_status
  694. acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  695. u64 *value, u32 width)
  696. {
  697. int result, size;
  698. u32 value32;
  699. if (!value)
  700. return AE_BAD_PARAMETER;
  701. switch (width) {
  702. case 8:
  703. size = 1;
  704. break;
  705. case 16:
  706. size = 2;
  707. break;
  708. case 32:
  709. size = 4;
  710. break;
  711. default:
  712. return AE_ERROR;
  713. }
  714. result = raw_pci_read(pci_id->segment, pci_id->bus,
  715. PCI_DEVFN(pci_id->device, pci_id->function),
  716. reg, size, &value32);
  717. *value = value32;
  718. return (result ? AE_ERROR : AE_OK);
  719. }
  720. acpi_status
  721. acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  722. u64 value, u32 width)
  723. {
  724. int result, size;
  725. switch (width) {
  726. case 8:
  727. size = 1;
  728. break;
  729. case 16:
  730. size = 2;
  731. break;
  732. case 32:
  733. size = 4;
  734. break;
  735. default:
  736. return AE_ERROR;
  737. }
  738. result = raw_pci_write(pci_id->segment, pci_id->bus,
  739. PCI_DEVFN(pci_id->device, pci_id->function),
  740. reg, size, value);
  741. return (result ? AE_ERROR : AE_OK);
  742. }
  743. static void acpi_os_execute_deferred(struct work_struct *work)
  744. {
  745. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  746. if (dpc->wait)
  747. acpi_os_wait_events_complete();
  748. dpc->function(dpc->context);
  749. kfree(dpc);
  750. }
  751. /*******************************************************************************
  752. *
  753. * FUNCTION: acpi_os_execute
  754. *
  755. * PARAMETERS: Type - Type of the callback
  756. * Function - Function to be executed
  757. * Context - Function parameters
  758. *
  759. * RETURN: Status
  760. *
  761. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  762. * immediately executes function on a separate thread.
  763. *
  764. ******************************************************************************/
  765. static acpi_status __acpi_os_execute(acpi_execute_type type,
  766. acpi_osd_exec_callback function, void *context, int hp)
  767. {
  768. acpi_status status = AE_OK;
  769. struct acpi_os_dpc *dpc;
  770. struct workqueue_struct *queue;
  771. int ret;
  772. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  773. "Scheduling function [%p(%p)] for deferred execution.\n",
  774. function, context));
  775. /*
  776. * Allocate/initialize DPC structure. Note that this memory will be
  777. * freed by the callee. The kernel handles the work_struct list in a
  778. * way that allows us to also free its memory inside the callee.
  779. * Because we may want to schedule several tasks with different
  780. * parameters we can't use the approach some kernel code uses of
  781. * having a static work_struct.
  782. */
  783. dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  784. if (!dpc)
  785. return AE_NO_MEMORY;
  786. dpc->function = function;
  787. dpc->context = context;
  788. /*
  789. * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
  790. * because the hotplug code may call driver .remove() functions,
  791. * which invoke flush_scheduled_work/acpi_os_wait_events_complete
  792. * to flush these workqueues.
  793. */
  794. queue = hp ? kacpi_hotplug_wq :
  795. (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
  796. dpc->wait = hp ? 1 : 0;
  797. if (queue == kacpi_hotplug_wq)
  798. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  799. else if (queue == kacpi_notify_wq)
  800. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  801. else
  802. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  803. /*
  804. * On some machines, a software-initiated SMI causes corruption unless
  805. * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
  806. * typically it's done in GPE-related methods that are run via
  807. * workqueues, so we can avoid the known corruption cases by always
  808. * queueing on CPU 0.
  809. */
  810. ret = queue_work_on(0, queue, &dpc->work);
  811. if (!ret) {
  812. printk(KERN_ERR PREFIX
  813. "Call to queue_work() failed.\n");
  814. status = AE_ERROR;
  815. kfree(dpc);
  816. }
  817. return status;
  818. }
  819. acpi_status acpi_os_execute(acpi_execute_type type,
  820. acpi_osd_exec_callback function, void *context)
  821. {
  822. return __acpi_os_execute(type, function, context, 0);
  823. }
  824. EXPORT_SYMBOL(acpi_os_execute);
  825. acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
  826. void *context)
  827. {
  828. return __acpi_os_execute(0, function, context, 1);
  829. }
  830. void acpi_os_wait_events_complete(void)
  831. {
  832. flush_workqueue(kacpid_wq);
  833. flush_workqueue(kacpi_notify_wq);
  834. }
  835. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  836. acpi_status
  837. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  838. {
  839. struct semaphore *sem = NULL;
  840. sem = acpi_os_allocate(sizeof(struct semaphore));
  841. if (!sem)
  842. return AE_NO_MEMORY;
  843. memset(sem, 0, sizeof(struct semaphore));
  844. sema_init(sem, initial_units);
  845. *handle = (acpi_handle *) sem;
  846. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  847. *handle, initial_units));
  848. return AE_OK;
  849. }
  850. /*
  851. * TODO: A better way to delete semaphores? Linux doesn't have a
  852. * 'delete_semaphore()' function -- may result in an invalid
  853. * pointer dereference for non-synchronized consumers. Should
  854. * we at least check for blocked threads and signal/cancel them?
  855. */
  856. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  857. {
  858. struct semaphore *sem = (struct semaphore *)handle;
  859. if (!sem)
  860. return AE_BAD_PARAMETER;
  861. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  862. BUG_ON(!list_empty(&sem->wait_list));
  863. kfree(sem);
  864. sem = NULL;
  865. return AE_OK;
  866. }
  867. /*
  868. * TODO: Support for units > 1?
  869. */
  870. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  871. {
  872. acpi_status status = AE_OK;
  873. struct semaphore *sem = (struct semaphore *)handle;
  874. long jiffies;
  875. int ret = 0;
  876. if (!sem || (units < 1))
  877. return AE_BAD_PARAMETER;
  878. if (units > 1)
  879. return AE_SUPPORT;
  880. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  881. handle, units, timeout));
  882. if (timeout == ACPI_WAIT_FOREVER)
  883. jiffies = MAX_SCHEDULE_TIMEOUT;
  884. else
  885. jiffies = msecs_to_jiffies(timeout);
  886. ret = down_timeout(sem, jiffies);
  887. if (ret)
  888. status = AE_TIME;
  889. if (ACPI_FAILURE(status)) {
  890. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  891. "Failed to acquire semaphore[%p|%d|%d], %s",
  892. handle, units, timeout,
  893. acpi_format_exception(status)));
  894. } else {
  895. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  896. "Acquired semaphore[%p|%d|%d]", handle,
  897. units, timeout));
  898. }
  899. return status;
  900. }
  901. /*
  902. * TODO: Support for units > 1?
  903. */
  904. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  905. {
  906. struct semaphore *sem = (struct semaphore *)handle;
  907. if (!sem || (units < 1))
  908. return AE_BAD_PARAMETER;
  909. if (units > 1)
  910. return AE_SUPPORT;
  911. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  912. units));
  913. up(sem);
  914. return AE_OK;
  915. }
  916. #ifdef ACPI_FUTURE_USAGE
  917. u32 acpi_os_get_line(char *buffer)
  918. {
  919. #ifdef ENABLE_DEBUGGER
  920. if (acpi_in_debugger) {
  921. u32 chars;
  922. kdb_read(buffer, sizeof(line_buf));
  923. /* remove the CR kdb includes */
  924. chars = strlen(buffer) - 1;
  925. buffer[chars] = '\0';
  926. }
  927. #endif
  928. return 0;
  929. }
  930. #endif /* ACPI_FUTURE_USAGE */
  931. acpi_status acpi_os_signal(u32 function, void *info)
  932. {
  933. switch (function) {
  934. case ACPI_SIGNAL_FATAL:
  935. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  936. break;
  937. case ACPI_SIGNAL_BREAKPOINT:
  938. /*
  939. * AML Breakpoint
  940. * ACPI spec. says to treat it as a NOP unless
  941. * you are debugging. So if/when we integrate
  942. * AML debugger into the kernel debugger its
  943. * hook will go here. But until then it is
  944. * not useful to print anything on breakpoints.
  945. */
  946. break;
  947. default:
  948. break;
  949. }
  950. return AE_OK;
  951. }
  952. static int __init acpi_os_name_setup(char *str)
  953. {
  954. char *p = acpi_os_name;
  955. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  956. if (!str || !*str)
  957. return 0;
  958. for (; count-- && str && *str; str++) {
  959. if (isalnum(*str) || *str == ' ' || *str == ':')
  960. *p++ = *str;
  961. else if (*str == '\'' || *str == '"')
  962. continue;
  963. else
  964. break;
  965. }
  966. *p = 0;
  967. return 1;
  968. }
  969. __setup("acpi_os_name=", acpi_os_name_setup);
  970. #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
  971. #define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
  972. struct osi_setup_entry {
  973. char string[OSI_STRING_LENGTH_MAX];
  974. bool enable;
  975. };
  976. static struct osi_setup_entry __initdata
  977. osi_setup_entries[OSI_STRING_ENTRIES_MAX] = {
  978. {"Module Device", true},
  979. {"Processor Device", true},
  980. {"3.0 _SCP Extensions", true},
  981. {"Processor Aggregator Device", true},
  982. };
  983. void __init acpi_osi_setup(char *str)
  984. {
  985. struct osi_setup_entry *osi;
  986. bool enable = true;
  987. int i;
  988. if (!acpi_gbl_create_osi_method)
  989. return;
  990. if (str == NULL || *str == '\0') {
  991. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  992. acpi_gbl_create_osi_method = FALSE;
  993. return;
  994. }
  995. if (*str == '!') {
  996. str++;
  997. enable = false;
  998. }
  999. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1000. osi = &osi_setup_entries[i];
  1001. if (!strcmp(osi->string, str)) {
  1002. osi->enable = enable;
  1003. break;
  1004. } else if (osi->string[0] == '\0') {
  1005. osi->enable = enable;
  1006. strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. static void __init set_osi_linux(unsigned int enable)
  1012. {
  1013. if (osi_linux.enable != enable)
  1014. osi_linux.enable = enable;
  1015. if (osi_linux.enable)
  1016. acpi_osi_setup("Linux");
  1017. else
  1018. acpi_osi_setup("!Linux");
  1019. return;
  1020. }
  1021. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  1022. {
  1023. osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
  1024. osi_linux.dmi = 0;
  1025. set_osi_linux(enable);
  1026. return;
  1027. }
  1028. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  1029. {
  1030. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  1031. if (enable == -1)
  1032. return;
  1033. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  1034. set_osi_linux(enable);
  1035. return;
  1036. }
  1037. /*
  1038. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  1039. *
  1040. * empty string disables _OSI
  1041. * string starting with '!' disables that string
  1042. * otherwise string is added to list, augmenting built-in strings
  1043. */
  1044. static void __init acpi_osi_setup_late(void)
  1045. {
  1046. struct osi_setup_entry *osi;
  1047. char *str;
  1048. int i;
  1049. acpi_status status;
  1050. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1051. osi = &osi_setup_entries[i];
  1052. str = osi->string;
  1053. if (*str == '\0')
  1054. break;
  1055. if (osi->enable) {
  1056. status = acpi_install_interface(str);
  1057. if (ACPI_SUCCESS(status))
  1058. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  1059. } else {
  1060. status = acpi_remove_interface(str);
  1061. if (ACPI_SUCCESS(status))
  1062. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  1063. }
  1064. }
  1065. }
  1066. static int __init osi_setup(char *str)
  1067. {
  1068. if (str && !strcmp("Linux", str))
  1069. acpi_cmdline_osi_linux(1);
  1070. else if (str && !strcmp("!Linux", str))
  1071. acpi_cmdline_osi_linux(0);
  1072. else
  1073. acpi_osi_setup(str);
  1074. return 1;
  1075. }
  1076. __setup("acpi_osi=", osi_setup);
  1077. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  1078. static int __init acpi_serialize_setup(char *str)
  1079. {
  1080. printk(KERN_INFO PREFIX "serialize enabled\n");
  1081. acpi_gbl_all_methods_serialized = TRUE;
  1082. return 1;
  1083. }
  1084. __setup("acpi_serialize", acpi_serialize_setup);
  1085. /* Check of resource interference between native drivers and ACPI
  1086. * OperationRegions (SystemIO and System Memory only).
  1087. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  1088. * in arbitrary AML code and can interfere with legacy drivers.
  1089. * acpi_enforce_resources= can be set to:
  1090. *
  1091. * - strict (default) (2)
  1092. * -> further driver trying to access the resources will not load
  1093. * - lax (1)
  1094. * -> further driver trying to access the resources will load, but you
  1095. * get a system message that something might go wrong...
  1096. *
  1097. * - no (0)
  1098. * -> ACPI Operation Region resources will not be registered
  1099. *
  1100. */
  1101. #define ENFORCE_RESOURCES_STRICT 2
  1102. #define ENFORCE_RESOURCES_LAX 1
  1103. #define ENFORCE_RESOURCES_NO 0
  1104. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1105. static int __init acpi_enforce_resources_setup(char *str)
  1106. {
  1107. if (str == NULL || *str == '\0')
  1108. return 0;
  1109. if (!strcmp("strict", str))
  1110. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1111. else if (!strcmp("lax", str))
  1112. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  1113. else if (!strcmp("no", str))
  1114. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  1115. return 1;
  1116. }
  1117. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  1118. /* Check for resource conflicts between ACPI OperationRegions and native
  1119. * drivers */
  1120. int acpi_check_resource_conflict(const struct resource *res)
  1121. {
  1122. acpi_adr_space_type space_id;
  1123. acpi_size length;
  1124. u8 warn = 0;
  1125. int clash = 0;
  1126. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1127. return 0;
  1128. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  1129. return 0;
  1130. if (res->flags & IORESOURCE_IO)
  1131. space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  1132. else
  1133. space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  1134. length = res->end - res->start + 1;
  1135. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
  1136. warn = 1;
  1137. clash = acpi_check_address_range(space_id, res->start, length, warn);
  1138. if (clash) {
  1139. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  1140. if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
  1141. printk(KERN_NOTICE "ACPI: This conflict may"
  1142. " cause random problems and system"
  1143. " instability\n");
  1144. printk(KERN_INFO "ACPI: If an ACPI driver is available"
  1145. " for this device, you should use it instead of"
  1146. " the native driver\n");
  1147. }
  1148. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  1149. return -EBUSY;
  1150. }
  1151. return 0;
  1152. }
  1153. EXPORT_SYMBOL(acpi_check_resource_conflict);
  1154. int acpi_check_region(resource_size_t start, resource_size_t n,
  1155. const char *name)
  1156. {
  1157. struct resource res = {
  1158. .start = start,
  1159. .end = start + n - 1,
  1160. .name = name,
  1161. .flags = IORESOURCE_IO,
  1162. };
  1163. return acpi_check_resource_conflict(&res);
  1164. }
  1165. EXPORT_SYMBOL(acpi_check_region);
  1166. /*
  1167. * Let drivers know whether the resource checks are effective
  1168. */
  1169. int acpi_resources_are_enforced(void)
  1170. {
  1171. return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
  1172. }
  1173. EXPORT_SYMBOL(acpi_resources_are_enforced);
  1174. /*
  1175. * Deallocate the memory for a spinlock.
  1176. */
  1177. void acpi_os_delete_lock(acpi_spinlock handle)
  1178. {
  1179. ACPI_FREE(handle);
  1180. }
  1181. /*
  1182. * Acquire a spinlock.
  1183. *
  1184. * handle is a pointer to the spinlock_t.
  1185. */
  1186. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1187. {
  1188. acpi_cpu_flags flags;
  1189. spin_lock_irqsave(lockp, flags);
  1190. return flags;
  1191. }
  1192. /*
  1193. * Release a spinlock. See above.
  1194. */
  1195. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1196. {
  1197. spin_unlock_irqrestore(lockp, flags);
  1198. }
  1199. #ifndef ACPI_USE_LOCAL_CACHE
  1200. /*******************************************************************************
  1201. *
  1202. * FUNCTION: acpi_os_create_cache
  1203. *
  1204. * PARAMETERS: name - Ascii name for the cache
  1205. * size - Size of each cached object
  1206. * depth - Maximum depth of the cache (in objects) <ignored>
  1207. * cache - Where the new cache object is returned
  1208. *
  1209. * RETURN: status
  1210. *
  1211. * DESCRIPTION: Create a cache object
  1212. *
  1213. ******************************************************************************/
  1214. acpi_status
  1215. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1216. {
  1217. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1218. if (*cache == NULL)
  1219. return AE_ERROR;
  1220. else
  1221. return AE_OK;
  1222. }
  1223. /*******************************************************************************
  1224. *
  1225. * FUNCTION: acpi_os_purge_cache
  1226. *
  1227. * PARAMETERS: Cache - Handle to cache object
  1228. *
  1229. * RETURN: Status
  1230. *
  1231. * DESCRIPTION: Free all objects within the requested cache.
  1232. *
  1233. ******************************************************************************/
  1234. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1235. {
  1236. kmem_cache_shrink(cache);
  1237. return (AE_OK);
  1238. }
  1239. /*******************************************************************************
  1240. *
  1241. * FUNCTION: acpi_os_delete_cache
  1242. *
  1243. * PARAMETERS: Cache - Handle to cache object
  1244. *
  1245. * RETURN: Status
  1246. *
  1247. * DESCRIPTION: Free all objects within the requested cache and delete the
  1248. * cache object.
  1249. *
  1250. ******************************************************************************/
  1251. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1252. {
  1253. kmem_cache_destroy(cache);
  1254. return (AE_OK);
  1255. }
  1256. /*******************************************************************************
  1257. *
  1258. * FUNCTION: acpi_os_release_object
  1259. *
  1260. * PARAMETERS: Cache - Handle to cache object
  1261. * Object - The object to be released
  1262. *
  1263. * RETURN: None
  1264. *
  1265. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1266. * the object is deleted.
  1267. *
  1268. ******************************************************************************/
  1269. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1270. {
  1271. kmem_cache_free(cache, object);
  1272. return (AE_OK);
  1273. }
  1274. #endif
  1275. acpi_status __init acpi_os_initialize(void)
  1276. {
  1277. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1278. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1279. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1280. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1281. return AE_OK;
  1282. }
  1283. acpi_status __init acpi_os_initialize1(void)
  1284. {
  1285. kacpid_wq = alloc_workqueue("kacpid", 0, 1);
  1286. kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
  1287. kacpi_hotplug_wq = alloc_workqueue("kacpi_hotplug", 0, 1);
  1288. BUG_ON(!kacpid_wq);
  1289. BUG_ON(!kacpi_notify_wq);
  1290. BUG_ON(!kacpi_hotplug_wq);
  1291. acpi_install_interface_handler(acpi_osi_handler);
  1292. acpi_osi_setup_late();
  1293. return AE_OK;
  1294. }
  1295. acpi_status acpi_os_terminate(void)
  1296. {
  1297. if (acpi_irq_handler) {
  1298. acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
  1299. acpi_irq_handler);
  1300. }
  1301. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1302. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1303. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1304. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1305. destroy_workqueue(kacpid_wq);
  1306. destroy_workqueue(kacpi_notify_wq);
  1307. destroy_workqueue(kacpi_hotplug_wq);
  1308. return AE_OK;
  1309. }
  1310. acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
  1311. u32 pm1b_control)
  1312. {
  1313. int rc = 0;
  1314. if (__acpi_os_prepare_sleep)
  1315. rc = __acpi_os_prepare_sleep(sleep_state,
  1316. pm1a_control, pm1b_control);
  1317. if (rc < 0)
  1318. return AE_ERROR;
  1319. else if (rc > 0)
  1320. return AE_CTRL_SKIP;
  1321. return AE_OK;
  1322. }
  1323. void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
  1324. u32 pm1a_ctrl, u32 pm1b_ctrl))
  1325. {
  1326. __acpi_os_prepare_sleep = func;
  1327. }