osl.c 34 KB

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