osl.c 42 KB

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