osl.c 41 KB

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