osl.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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. acpi_status
  466. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  467. acpi_physical_address * new_address,
  468. u32 *new_table_length)
  469. {
  470. return AE_SUPPORT;
  471. }
  472. static irqreturn_t acpi_irq(int irq, void *dev_id)
  473. {
  474. u32 handled;
  475. handled = (*acpi_irq_handler) (acpi_irq_context);
  476. if (handled) {
  477. acpi_irq_handled++;
  478. return IRQ_HANDLED;
  479. } else {
  480. acpi_irq_not_handled++;
  481. return IRQ_NONE;
  482. }
  483. }
  484. acpi_status
  485. acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
  486. void *context)
  487. {
  488. unsigned int irq;
  489. acpi_irq_stats_init();
  490. /*
  491. * ACPI interrupts different from the SCI in our copy of the FADT are
  492. * not supported.
  493. */
  494. if (gsi != acpi_gbl_FADT.sci_interrupt)
  495. return AE_BAD_PARAMETER;
  496. if (acpi_irq_handler)
  497. return AE_ALREADY_ACQUIRED;
  498. if (acpi_gsi_to_irq(gsi, &irq) < 0) {
  499. printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
  500. gsi);
  501. return AE_OK;
  502. }
  503. acpi_irq_handler = handler;
  504. acpi_irq_context = context;
  505. if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
  506. printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
  507. acpi_irq_handler = NULL;
  508. return AE_NOT_ACQUIRED;
  509. }
  510. return AE_OK;
  511. }
  512. acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
  513. {
  514. if (irq != acpi_gbl_FADT.sci_interrupt)
  515. return AE_BAD_PARAMETER;
  516. free_irq(irq, acpi_irq);
  517. acpi_irq_handler = NULL;
  518. return AE_OK;
  519. }
  520. /*
  521. * Running in interpreter thread context, safe to sleep
  522. */
  523. void acpi_os_sleep(u64 ms)
  524. {
  525. schedule_timeout_interruptible(msecs_to_jiffies(ms));
  526. }
  527. void acpi_os_stall(u32 us)
  528. {
  529. while (us) {
  530. u32 delay = 1000;
  531. if (delay > us)
  532. delay = us;
  533. udelay(delay);
  534. touch_nmi_watchdog();
  535. us -= delay;
  536. }
  537. }
  538. /*
  539. * Support ACPI 3.0 AML Timer operand
  540. * Returns 64-bit free-running, monotonically increasing timer
  541. * with 100ns granularity
  542. */
  543. u64 acpi_os_get_timer(void)
  544. {
  545. static u64 t;
  546. #ifdef CONFIG_HPET
  547. /* TBD: use HPET if available */
  548. #endif
  549. #ifdef CONFIG_X86_PM_TIMER
  550. /* TBD: default to PM timer if HPET was not available */
  551. #endif
  552. if (!t)
  553. printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
  554. return ++t;
  555. }
  556. acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  557. {
  558. u32 dummy;
  559. if (!value)
  560. value = &dummy;
  561. *value = 0;
  562. if (width <= 8) {
  563. *(u8 *) value = inb(port);
  564. } else if (width <= 16) {
  565. *(u16 *) value = inw(port);
  566. } else if (width <= 32) {
  567. *(u32 *) value = inl(port);
  568. } else {
  569. BUG();
  570. }
  571. return AE_OK;
  572. }
  573. EXPORT_SYMBOL(acpi_os_read_port);
  574. acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  575. {
  576. if (width <= 8) {
  577. outb(value, port);
  578. } else if (width <= 16) {
  579. outw(value, port);
  580. } else if (width <= 32) {
  581. outl(value, port);
  582. } else {
  583. BUG();
  584. }
  585. return AE_OK;
  586. }
  587. EXPORT_SYMBOL(acpi_os_write_port);
  588. #ifdef readq
  589. static inline u64 read64(const volatile void __iomem *addr)
  590. {
  591. return readq(addr);
  592. }
  593. #else
  594. static inline u64 read64(const volatile void __iomem *addr)
  595. {
  596. u64 l, h;
  597. l = readl(addr);
  598. h = readl(addr+4);
  599. return l | (h << 32);
  600. }
  601. #endif
  602. acpi_status
  603. acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
  604. {
  605. void __iomem *virt_addr;
  606. unsigned int size = width / 8;
  607. bool unmap = false;
  608. u64 dummy;
  609. rcu_read_lock();
  610. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  611. if (!virt_addr) {
  612. rcu_read_unlock();
  613. virt_addr = acpi_os_ioremap(phys_addr, size);
  614. if (!virt_addr)
  615. return AE_BAD_ADDRESS;
  616. unmap = true;
  617. }
  618. if (!value)
  619. value = &dummy;
  620. switch (width) {
  621. case 8:
  622. *(u8 *) value = readb(virt_addr);
  623. break;
  624. case 16:
  625. *(u16 *) value = readw(virt_addr);
  626. break;
  627. case 32:
  628. *(u32 *) value = readl(virt_addr);
  629. break;
  630. case 64:
  631. *(u64 *) value = read64(virt_addr);
  632. break;
  633. default:
  634. BUG();
  635. }
  636. if (unmap)
  637. iounmap(virt_addr);
  638. else
  639. rcu_read_unlock();
  640. return AE_OK;
  641. }
  642. #ifdef writeq
  643. static inline void write64(u64 val, volatile void __iomem *addr)
  644. {
  645. writeq(val, addr);
  646. }
  647. #else
  648. static inline void write64(u64 val, volatile void __iomem *addr)
  649. {
  650. writel(val, addr);
  651. writel(val>>32, addr+4);
  652. }
  653. #endif
  654. acpi_status
  655. acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
  656. {
  657. void __iomem *virt_addr;
  658. unsigned int size = width / 8;
  659. bool unmap = false;
  660. rcu_read_lock();
  661. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  662. if (!virt_addr) {
  663. rcu_read_unlock();
  664. virt_addr = acpi_os_ioremap(phys_addr, size);
  665. if (!virt_addr)
  666. return AE_BAD_ADDRESS;
  667. unmap = true;
  668. }
  669. switch (width) {
  670. case 8:
  671. writeb(value, virt_addr);
  672. break;
  673. case 16:
  674. writew(value, virt_addr);
  675. break;
  676. case 32:
  677. writel(value, virt_addr);
  678. break;
  679. case 64:
  680. write64(value, virt_addr);
  681. break;
  682. default:
  683. BUG();
  684. }
  685. if (unmap)
  686. iounmap(virt_addr);
  687. else
  688. rcu_read_unlock();
  689. return AE_OK;
  690. }
  691. acpi_status
  692. acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  693. u64 *value, u32 width)
  694. {
  695. int result, size;
  696. u32 value32;
  697. if (!value)
  698. return AE_BAD_PARAMETER;
  699. switch (width) {
  700. case 8:
  701. size = 1;
  702. break;
  703. case 16:
  704. size = 2;
  705. break;
  706. case 32:
  707. size = 4;
  708. break;
  709. default:
  710. return AE_ERROR;
  711. }
  712. result = raw_pci_read(pci_id->segment, pci_id->bus,
  713. PCI_DEVFN(pci_id->device, pci_id->function),
  714. reg, size, &value32);
  715. *value = value32;
  716. return (result ? AE_ERROR : AE_OK);
  717. }
  718. acpi_status
  719. acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  720. u64 value, u32 width)
  721. {
  722. int result, size;
  723. switch (width) {
  724. case 8:
  725. size = 1;
  726. break;
  727. case 16:
  728. size = 2;
  729. break;
  730. case 32:
  731. size = 4;
  732. break;
  733. default:
  734. return AE_ERROR;
  735. }
  736. result = raw_pci_write(pci_id->segment, pci_id->bus,
  737. PCI_DEVFN(pci_id->device, pci_id->function),
  738. reg, size, value);
  739. return (result ? AE_ERROR : AE_OK);
  740. }
  741. static void acpi_os_execute_deferred(struct work_struct *work)
  742. {
  743. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  744. if (dpc->wait)
  745. acpi_os_wait_events_complete(NULL);
  746. dpc->function(dpc->context);
  747. kfree(dpc);
  748. }
  749. /*******************************************************************************
  750. *
  751. * FUNCTION: acpi_os_execute
  752. *
  753. * PARAMETERS: Type - Type of the callback
  754. * Function - Function to be executed
  755. * Context - Function parameters
  756. *
  757. * RETURN: Status
  758. *
  759. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  760. * immediately executes function on a separate thread.
  761. *
  762. ******************************************************************************/
  763. static acpi_status __acpi_os_execute(acpi_execute_type type,
  764. acpi_osd_exec_callback function, void *context, int hp)
  765. {
  766. acpi_status status = AE_OK;
  767. struct acpi_os_dpc *dpc;
  768. struct workqueue_struct *queue;
  769. int ret;
  770. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  771. "Scheduling function [%p(%p)] for deferred execution.\n",
  772. function, context));
  773. /*
  774. * Allocate/initialize DPC structure. Note that this memory will be
  775. * freed by the callee. The kernel handles the work_struct list in a
  776. * way that allows us to also free its memory inside the callee.
  777. * Because we may want to schedule several tasks with different
  778. * parameters we can't use the approach some kernel code uses of
  779. * having a static work_struct.
  780. */
  781. dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  782. if (!dpc)
  783. return AE_NO_MEMORY;
  784. dpc->function = function;
  785. dpc->context = context;
  786. /*
  787. * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
  788. * because the hotplug code may call driver .remove() functions,
  789. * which invoke flush_scheduled_work/acpi_os_wait_events_complete
  790. * to flush these workqueues.
  791. */
  792. queue = hp ? kacpi_hotplug_wq :
  793. (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
  794. dpc->wait = hp ? 1 : 0;
  795. if (queue == kacpi_hotplug_wq)
  796. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  797. else if (queue == kacpi_notify_wq)
  798. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  799. else
  800. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  801. /*
  802. * On some machines, a software-initiated SMI causes corruption unless
  803. * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
  804. * typically it's done in GPE-related methods that are run via
  805. * workqueues, so we can avoid the known corruption cases by always
  806. * queueing on CPU 0.
  807. */
  808. ret = queue_work_on(0, queue, &dpc->work);
  809. if (!ret) {
  810. printk(KERN_ERR PREFIX
  811. "Call to queue_work() failed.\n");
  812. status = AE_ERROR;
  813. kfree(dpc);
  814. }
  815. return status;
  816. }
  817. acpi_status acpi_os_execute(acpi_execute_type type,
  818. acpi_osd_exec_callback function, void *context)
  819. {
  820. return __acpi_os_execute(type, function, context, 0);
  821. }
  822. EXPORT_SYMBOL(acpi_os_execute);
  823. acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
  824. void *context)
  825. {
  826. return __acpi_os_execute(0, function, context, 1);
  827. }
  828. void acpi_os_wait_events_complete(void *context)
  829. {
  830. flush_workqueue(kacpid_wq);
  831. flush_workqueue(kacpi_notify_wq);
  832. }
  833. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  834. acpi_status
  835. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  836. {
  837. struct semaphore *sem = NULL;
  838. sem = acpi_os_allocate(sizeof(struct semaphore));
  839. if (!sem)
  840. return AE_NO_MEMORY;
  841. memset(sem, 0, sizeof(struct semaphore));
  842. sema_init(sem, initial_units);
  843. *handle = (acpi_handle *) sem;
  844. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  845. *handle, initial_units));
  846. return AE_OK;
  847. }
  848. /*
  849. * TODO: A better way to delete semaphores? Linux doesn't have a
  850. * 'delete_semaphore()' function -- may result in an invalid
  851. * pointer dereference for non-synchronized consumers. Should
  852. * we at least check for blocked threads and signal/cancel them?
  853. */
  854. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  855. {
  856. struct semaphore *sem = (struct semaphore *)handle;
  857. if (!sem)
  858. return AE_BAD_PARAMETER;
  859. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  860. BUG_ON(!list_empty(&sem->wait_list));
  861. kfree(sem);
  862. sem = NULL;
  863. return AE_OK;
  864. }
  865. /*
  866. * TODO: Support for units > 1?
  867. */
  868. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  869. {
  870. acpi_status status = AE_OK;
  871. struct semaphore *sem = (struct semaphore *)handle;
  872. long jiffies;
  873. int ret = 0;
  874. if (!sem || (units < 1))
  875. return AE_BAD_PARAMETER;
  876. if (units > 1)
  877. return AE_SUPPORT;
  878. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  879. handle, units, timeout));
  880. if (timeout == ACPI_WAIT_FOREVER)
  881. jiffies = MAX_SCHEDULE_TIMEOUT;
  882. else
  883. jiffies = msecs_to_jiffies(timeout);
  884. ret = down_timeout(sem, jiffies);
  885. if (ret)
  886. status = AE_TIME;
  887. if (ACPI_FAILURE(status)) {
  888. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  889. "Failed to acquire semaphore[%p|%d|%d], %s",
  890. handle, units, timeout,
  891. acpi_format_exception(status)));
  892. } else {
  893. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  894. "Acquired semaphore[%p|%d|%d]", handle,
  895. units, timeout));
  896. }
  897. return status;
  898. }
  899. /*
  900. * TODO: Support for units > 1?
  901. */
  902. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  903. {
  904. struct semaphore *sem = (struct semaphore *)handle;
  905. if (!sem || (units < 1))
  906. return AE_BAD_PARAMETER;
  907. if (units > 1)
  908. return AE_SUPPORT;
  909. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  910. units));
  911. up(sem);
  912. return AE_OK;
  913. }
  914. #ifdef ACPI_FUTURE_USAGE
  915. u32 acpi_os_get_line(char *buffer)
  916. {
  917. #ifdef ENABLE_DEBUGGER
  918. if (acpi_in_debugger) {
  919. u32 chars;
  920. kdb_read(buffer, sizeof(line_buf));
  921. /* remove the CR kdb includes */
  922. chars = strlen(buffer) - 1;
  923. buffer[chars] = '\0';
  924. }
  925. #endif
  926. return 0;
  927. }
  928. #endif /* ACPI_FUTURE_USAGE */
  929. acpi_status acpi_os_signal(u32 function, void *info)
  930. {
  931. switch (function) {
  932. case ACPI_SIGNAL_FATAL:
  933. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  934. break;
  935. case ACPI_SIGNAL_BREAKPOINT:
  936. /*
  937. * AML Breakpoint
  938. * ACPI spec. says to treat it as a NOP unless
  939. * you are debugging. So if/when we integrate
  940. * AML debugger into the kernel debugger its
  941. * hook will go here. But until then it is
  942. * not useful to print anything on breakpoints.
  943. */
  944. break;
  945. default:
  946. break;
  947. }
  948. return AE_OK;
  949. }
  950. static int __init acpi_os_name_setup(char *str)
  951. {
  952. char *p = acpi_os_name;
  953. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  954. if (!str || !*str)
  955. return 0;
  956. for (; count-- && str && *str; str++) {
  957. if (isalnum(*str) || *str == ' ' || *str == ':')
  958. *p++ = *str;
  959. else if (*str == '\'' || *str == '"')
  960. continue;
  961. else
  962. break;
  963. }
  964. *p = 0;
  965. return 1;
  966. }
  967. __setup("acpi_os_name=", acpi_os_name_setup);
  968. #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
  969. #define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
  970. struct osi_setup_entry {
  971. char string[OSI_STRING_LENGTH_MAX];
  972. bool enable;
  973. };
  974. static struct osi_setup_entry __initdata
  975. osi_setup_entries[OSI_STRING_ENTRIES_MAX] = {
  976. {"Module Device", true},
  977. {"Processor Device", true},
  978. {"3.0 _SCP Extensions", true},
  979. {"Processor Aggregator Device", true},
  980. };
  981. void __init acpi_osi_setup(char *str)
  982. {
  983. struct osi_setup_entry *osi;
  984. bool enable = true;
  985. int i;
  986. if (!acpi_gbl_create_osi_method)
  987. return;
  988. if (str == NULL || *str == '\0') {
  989. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  990. acpi_gbl_create_osi_method = FALSE;
  991. return;
  992. }
  993. if (*str == '!') {
  994. str++;
  995. enable = false;
  996. }
  997. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  998. osi = &osi_setup_entries[i];
  999. if (!strcmp(osi->string, str)) {
  1000. osi->enable = enable;
  1001. break;
  1002. } else if (osi->string[0] == '\0') {
  1003. osi->enable = enable;
  1004. strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
  1005. break;
  1006. }
  1007. }
  1008. }
  1009. static void __init set_osi_linux(unsigned int enable)
  1010. {
  1011. if (osi_linux.enable != enable)
  1012. osi_linux.enable = enable;
  1013. if (osi_linux.enable)
  1014. acpi_osi_setup("Linux");
  1015. else
  1016. acpi_osi_setup("!Linux");
  1017. return;
  1018. }
  1019. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  1020. {
  1021. osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
  1022. osi_linux.dmi = 0;
  1023. set_osi_linux(enable);
  1024. return;
  1025. }
  1026. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  1027. {
  1028. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  1029. if (enable == -1)
  1030. return;
  1031. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  1032. set_osi_linux(enable);
  1033. return;
  1034. }
  1035. /*
  1036. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  1037. *
  1038. * empty string disables _OSI
  1039. * string starting with '!' disables that string
  1040. * otherwise string is added to list, augmenting built-in strings
  1041. */
  1042. static void __init acpi_osi_setup_late(void)
  1043. {
  1044. struct osi_setup_entry *osi;
  1045. char *str;
  1046. int i;
  1047. acpi_status status;
  1048. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1049. osi = &osi_setup_entries[i];
  1050. str = osi->string;
  1051. if (*str == '\0')
  1052. break;
  1053. if (osi->enable) {
  1054. status = acpi_install_interface(str);
  1055. if (ACPI_SUCCESS(status))
  1056. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  1057. } else {
  1058. status = acpi_remove_interface(str);
  1059. if (ACPI_SUCCESS(status))
  1060. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  1061. }
  1062. }
  1063. }
  1064. static int __init osi_setup(char *str)
  1065. {
  1066. if (str && !strcmp("Linux", str))
  1067. acpi_cmdline_osi_linux(1);
  1068. else if (str && !strcmp("!Linux", str))
  1069. acpi_cmdline_osi_linux(0);
  1070. else
  1071. acpi_osi_setup(str);
  1072. return 1;
  1073. }
  1074. __setup("acpi_osi=", osi_setup);
  1075. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  1076. static int __init acpi_serialize_setup(char *str)
  1077. {
  1078. printk(KERN_INFO PREFIX "serialize enabled\n");
  1079. acpi_gbl_all_methods_serialized = TRUE;
  1080. return 1;
  1081. }
  1082. __setup("acpi_serialize", acpi_serialize_setup);
  1083. /* Check of resource interference between native drivers and ACPI
  1084. * OperationRegions (SystemIO and System Memory only).
  1085. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  1086. * in arbitrary AML code and can interfere with legacy drivers.
  1087. * acpi_enforce_resources= can be set to:
  1088. *
  1089. * - strict (default) (2)
  1090. * -> further driver trying to access the resources will not load
  1091. * - lax (1)
  1092. * -> further driver trying to access the resources will load, but you
  1093. * get a system message that something might go wrong...
  1094. *
  1095. * - no (0)
  1096. * -> ACPI Operation Region resources will not be registered
  1097. *
  1098. */
  1099. #define ENFORCE_RESOURCES_STRICT 2
  1100. #define ENFORCE_RESOURCES_LAX 1
  1101. #define ENFORCE_RESOURCES_NO 0
  1102. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1103. static int __init acpi_enforce_resources_setup(char *str)
  1104. {
  1105. if (str == NULL || *str == '\0')
  1106. return 0;
  1107. if (!strcmp("strict", str))
  1108. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1109. else if (!strcmp("lax", str))
  1110. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  1111. else if (!strcmp("no", str))
  1112. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  1113. return 1;
  1114. }
  1115. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  1116. /* Check for resource conflicts between ACPI OperationRegions and native
  1117. * drivers */
  1118. int acpi_check_resource_conflict(const struct resource *res)
  1119. {
  1120. acpi_adr_space_type space_id;
  1121. acpi_size length;
  1122. u8 warn = 0;
  1123. int clash = 0;
  1124. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1125. return 0;
  1126. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  1127. return 0;
  1128. if (res->flags & IORESOURCE_IO)
  1129. space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  1130. else
  1131. space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  1132. length = res->end - res->start + 1;
  1133. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
  1134. warn = 1;
  1135. clash = acpi_check_address_range(space_id, res->start, length, warn);
  1136. if (clash) {
  1137. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  1138. if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
  1139. printk(KERN_NOTICE "ACPI: This conflict may"
  1140. " cause random problems and system"
  1141. " instability\n");
  1142. printk(KERN_INFO "ACPI: If an ACPI driver is available"
  1143. " for this device, you should use it instead of"
  1144. " the native driver\n");
  1145. }
  1146. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  1147. return -EBUSY;
  1148. }
  1149. return 0;
  1150. }
  1151. EXPORT_SYMBOL(acpi_check_resource_conflict);
  1152. int acpi_check_region(resource_size_t start, resource_size_t n,
  1153. const char *name)
  1154. {
  1155. struct resource res = {
  1156. .start = start,
  1157. .end = start + n - 1,
  1158. .name = name,
  1159. .flags = IORESOURCE_IO,
  1160. };
  1161. return acpi_check_resource_conflict(&res);
  1162. }
  1163. EXPORT_SYMBOL(acpi_check_region);
  1164. /*
  1165. * Let drivers know whether the resource checks are effective
  1166. */
  1167. int acpi_resources_are_enforced(void)
  1168. {
  1169. return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
  1170. }
  1171. EXPORT_SYMBOL(acpi_resources_are_enforced);
  1172. /*
  1173. * Deallocate the memory for a spinlock.
  1174. */
  1175. void acpi_os_delete_lock(acpi_spinlock handle)
  1176. {
  1177. ACPI_FREE(handle);
  1178. }
  1179. /*
  1180. * Acquire a spinlock.
  1181. *
  1182. * handle is a pointer to the spinlock_t.
  1183. */
  1184. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1185. {
  1186. acpi_cpu_flags flags;
  1187. spin_lock_irqsave(lockp, flags);
  1188. return flags;
  1189. }
  1190. /*
  1191. * Release a spinlock. See above.
  1192. */
  1193. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1194. {
  1195. spin_unlock_irqrestore(lockp, flags);
  1196. }
  1197. #ifndef ACPI_USE_LOCAL_CACHE
  1198. /*******************************************************************************
  1199. *
  1200. * FUNCTION: acpi_os_create_cache
  1201. *
  1202. * PARAMETERS: name - Ascii name for the cache
  1203. * size - Size of each cached object
  1204. * depth - Maximum depth of the cache (in objects) <ignored>
  1205. * cache - Where the new cache object is returned
  1206. *
  1207. * RETURN: status
  1208. *
  1209. * DESCRIPTION: Create a cache object
  1210. *
  1211. ******************************************************************************/
  1212. acpi_status
  1213. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1214. {
  1215. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1216. if (*cache == NULL)
  1217. return AE_ERROR;
  1218. else
  1219. return AE_OK;
  1220. }
  1221. /*******************************************************************************
  1222. *
  1223. * FUNCTION: acpi_os_purge_cache
  1224. *
  1225. * PARAMETERS: Cache - Handle to cache object
  1226. *
  1227. * RETURN: Status
  1228. *
  1229. * DESCRIPTION: Free all objects within the requested cache.
  1230. *
  1231. ******************************************************************************/
  1232. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1233. {
  1234. kmem_cache_shrink(cache);
  1235. return (AE_OK);
  1236. }
  1237. /*******************************************************************************
  1238. *
  1239. * FUNCTION: acpi_os_delete_cache
  1240. *
  1241. * PARAMETERS: Cache - Handle to cache object
  1242. *
  1243. * RETURN: Status
  1244. *
  1245. * DESCRIPTION: Free all objects within the requested cache and delete the
  1246. * cache object.
  1247. *
  1248. ******************************************************************************/
  1249. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1250. {
  1251. kmem_cache_destroy(cache);
  1252. return (AE_OK);
  1253. }
  1254. /*******************************************************************************
  1255. *
  1256. * FUNCTION: acpi_os_release_object
  1257. *
  1258. * PARAMETERS: Cache - Handle to cache object
  1259. * Object - The object to be released
  1260. *
  1261. * RETURN: None
  1262. *
  1263. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1264. * the object is deleted.
  1265. *
  1266. ******************************************************************************/
  1267. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1268. {
  1269. kmem_cache_free(cache, object);
  1270. return (AE_OK);
  1271. }
  1272. #endif
  1273. acpi_status __init acpi_os_initialize(void)
  1274. {
  1275. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1276. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1277. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1278. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1279. return AE_OK;
  1280. }
  1281. acpi_status __init acpi_os_initialize1(void)
  1282. {
  1283. kacpid_wq = alloc_workqueue("kacpid", 0, 1);
  1284. kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
  1285. kacpi_hotplug_wq = alloc_workqueue("kacpi_hotplug", 0, 1);
  1286. BUG_ON(!kacpid_wq);
  1287. BUG_ON(!kacpi_notify_wq);
  1288. BUG_ON(!kacpi_hotplug_wq);
  1289. acpi_install_interface_handler(acpi_osi_handler);
  1290. acpi_osi_setup_late();
  1291. return AE_OK;
  1292. }
  1293. acpi_status acpi_os_terminate(void)
  1294. {
  1295. if (acpi_irq_handler) {
  1296. acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
  1297. acpi_irq_handler);
  1298. }
  1299. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1300. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1301. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1302. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1303. destroy_workqueue(kacpid_wq);
  1304. destroy_workqueue(kacpi_notify_wq);
  1305. destroy_workqueue(kacpi_hotplug_wq);
  1306. return AE_OK;
  1307. }