osl.c 36 KB

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