osl.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226
  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. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. *
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <linux/mm.h>
  29. #include <linux/highmem.h>
  30. #include <linux/pci.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/kmod.h>
  33. #include <linux/delay.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/nmi.h>
  36. #include <linux/acpi.h>
  37. #include <linux/efi.h>
  38. #include <linux/ioport.h>
  39. #include <linux/list.h>
  40. #include <linux/jiffies.h>
  41. #include <linux/semaphore.h>
  42. #include <asm/io.h>
  43. #include <asm/uaccess.h>
  44. #include <linux/io-64-nonatomic-lo-hi.h>
  45. #include "internal.h"
  46. #define _COMPONENT ACPI_OS_SERVICES
  47. ACPI_MODULE_NAME("osl");
  48. struct acpi_os_dpc {
  49. acpi_osd_exec_callback function;
  50. void *context;
  51. struct work_struct work;
  52. };
  53. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  54. #include CONFIG_ACPI_CUSTOM_DSDT_FILE
  55. #endif
  56. #ifdef ENABLE_DEBUGGER
  57. #include <linux/kdb.h>
  58. /* stuff for debugger support */
  59. int acpi_in_debugger;
  60. EXPORT_SYMBOL(acpi_in_debugger);
  61. #endif /*ENABLE_DEBUGGER */
  62. static int (*__acpi_os_prepare_sleep)(u8 sleep_state, u32 pm1a_ctrl,
  63. u32 pm1b_ctrl);
  64. static int (*__acpi_os_prepare_extended_sleep)(u8 sleep_state, u32 val_a,
  65. u32 val_b);
  66. static acpi_osd_handler acpi_irq_handler;
  67. static void *acpi_irq_context;
  68. static struct workqueue_struct *kacpid_wq;
  69. static struct workqueue_struct *kacpi_notify_wq;
  70. static struct workqueue_struct *kacpi_hotplug_wq;
  71. static bool acpi_os_initialized;
  72. unsigned int acpi_sci_irq = INVALID_ACPI_IRQ;
  73. /*
  74. * This list of permanent mappings is for memory that may be accessed from
  75. * interrupt context, where we can't do the ioremap().
  76. */
  77. struct acpi_ioremap {
  78. struct list_head list;
  79. void __iomem *virt;
  80. acpi_physical_address phys;
  81. acpi_size size;
  82. unsigned long refcount;
  83. };
  84. static LIST_HEAD(acpi_ioremaps);
  85. static DEFINE_MUTEX(acpi_ioremap_lock);
  86. static void __init acpi_osi_setup_late(void);
  87. /*
  88. * The story of _OSI(Linux)
  89. *
  90. * From pre-history through Linux-2.6.22,
  91. * Linux responded TRUE upon a BIOS OSI(Linux) query.
  92. *
  93. * Unfortunately, reference BIOS writers got wind of this
  94. * and put OSI(Linux) in their example code, quickly exposing
  95. * this string as ill-conceived and opening the door to
  96. * an un-bounded number of BIOS incompatibilities.
  97. *
  98. * For example, OSI(Linux) was used on resume to re-POST a
  99. * video card on one system, because Linux at that time
  100. * could not do a speedy restore in its native driver.
  101. * But then upon gaining quick native restore capability,
  102. * Linux has no way to tell the BIOS to skip the time-consuming
  103. * POST -- putting Linux at a permanent performance disadvantage.
  104. * On another system, the BIOS writer used OSI(Linux)
  105. * to infer native OS support for IPMI! On other systems,
  106. * OSI(Linux) simply got in the way of Linux claiming to
  107. * be compatible with other operating systems, exposing
  108. * BIOS issues such as skipped device initialization.
  109. *
  110. * So "Linux" turned out to be a really poor chose of
  111. * OSI string, and from Linux-2.6.23 onward we respond FALSE.
  112. *
  113. * BIOS writers should NOT query _OSI(Linux) on future systems.
  114. * Linux will complain on the console when it sees it, and return FALSE.
  115. * To get Linux to return TRUE for your system will require
  116. * a kernel source update to add a DMI entry,
  117. * or boot with "acpi_osi=Linux"
  118. */
  119. static struct osi_linux {
  120. unsigned int enable:1;
  121. unsigned int dmi:1;
  122. unsigned int cmdline:1;
  123. unsigned int default_disabling:1;
  124. } osi_linux = {0, 0, 0, 0};
  125. static u32 acpi_osi_handler(acpi_string interface, u32 supported)
  126. {
  127. if (!strcmp("Linux", interface)) {
  128. printk_once(KERN_NOTICE FW_BUG PREFIX
  129. "BIOS _OSI(Linux) query %s%s\n",
  130. osi_linux.enable ? "honored" : "ignored",
  131. osi_linux.cmdline ? " via cmdline" :
  132. osi_linux.dmi ? " via DMI" : "");
  133. }
  134. if (!strcmp("Darwin", interface)) {
  135. /*
  136. * Apple firmware will behave poorly if it receives positive
  137. * answers to "Darwin" and any other OS. Respond positively
  138. * to Darwin and then disable all other vendor strings.
  139. */
  140. acpi_update_interfaces(ACPI_DISABLE_ALL_VENDOR_STRINGS);
  141. supported = ACPI_UINT32_MAX;
  142. }
  143. return supported;
  144. }
  145. static void __init acpi_request_region (struct acpi_generic_address *gas,
  146. unsigned int length, char *desc)
  147. {
  148. u64 addr;
  149. /* Handle possible alignment issues */
  150. memcpy(&addr, &gas->address, sizeof(addr));
  151. if (!addr || !length)
  152. return;
  153. /* Resources are never freed */
  154. if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  155. request_region(addr, length, desc);
  156. else if (gas->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
  157. request_mem_region(addr, length, desc);
  158. }
  159. static int __init acpi_reserve_resources(void)
  160. {
  161. acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
  162. "ACPI PM1a_EVT_BLK");
  163. acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
  164. "ACPI PM1b_EVT_BLK");
  165. acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
  166. "ACPI PM1a_CNT_BLK");
  167. acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
  168. "ACPI PM1b_CNT_BLK");
  169. if (acpi_gbl_FADT.pm_timer_length == 4)
  170. acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
  171. acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
  172. "ACPI PM2_CNT_BLK");
  173. /* Length of GPE blocks must be a non-negative multiple of 2 */
  174. if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
  175. acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
  176. acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
  177. if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
  178. acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
  179. acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
  180. return 0;
  181. }
  182. fs_initcall_sync(acpi_reserve_resources);
  183. void acpi_os_printf(const char *fmt, ...)
  184. {
  185. va_list args;
  186. va_start(args, fmt);
  187. acpi_os_vprintf(fmt, args);
  188. va_end(args);
  189. }
  190. EXPORT_SYMBOL(acpi_os_printf);
  191. void acpi_os_vprintf(const char *fmt, va_list args)
  192. {
  193. static char buffer[512];
  194. vsprintf(buffer, fmt, args);
  195. #ifdef ENABLE_DEBUGGER
  196. if (acpi_in_debugger) {
  197. kdb_printf("%s", buffer);
  198. } else {
  199. printk(KERN_CONT "%s", buffer);
  200. }
  201. #else
  202. if (acpi_debugger_write_log(buffer) < 0)
  203. printk(KERN_CONT "%s", buffer);
  204. #endif
  205. }
  206. #ifdef CONFIG_KEXEC
  207. static unsigned long acpi_rsdp;
  208. static int __init setup_acpi_rsdp(char *arg)
  209. {
  210. if (kstrtoul(arg, 16, &acpi_rsdp))
  211. return -EINVAL;
  212. return 0;
  213. }
  214. early_param("acpi_rsdp", setup_acpi_rsdp);
  215. #endif
  216. acpi_physical_address __init acpi_os_get_root_pointer(void)
  217. {
  218. #ifdef CONFIG_KEXEC
  219. if (acpi_rsdp)
  220. return acpi_rsdp;
  221. #endif
  222. if (efi_enabled(EFI_CONFIG_TABLES)) {
  223. if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  224. return efi.acpi20;
  225. else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  226. return efi.acpi;
  227. else {
  228. printk(KERN_ERR PREFIX
  229. "System description tables not found\n");
  230. return 0;
  231. }
  232. } else if (IS_ENABLED(CONFIG_ACPI_LEGACY_TABLES_LOOKUP)) {
  233. acpi_physical_address pa = 0;
  234. acpi_find_root_pointer(&pa);
  235. return pa;
  236. }
  237. return 0;
  238. }
  239. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  240. static struct acpi_ioremap *
  241. acpi_map_lookup(acpi_physical_address phys, acpi_size size)
  242. {
  243. struct acpi_ioremap *map;
  244. list_for_each_entry_rcu(map, &acpi_ioremaps, list)
  245. if (map->phys <= phys &&
  246. phys + size <= map->phys + map->size)
  247. return map;
  248. return NULL;
  249. }
  250. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  251. static void __iomem *
  252. acpi_map_vaddr_lookup(acpi_physical_address phys, unsigned int size)
  253. {
  254. struct acpi_ioremap *map;
  255. map = acpi_map_lookup(phys, size);
  256. if (map)
  257. return map->virt + (phys - map->phys);
  258. return NULL;
  259. }
  260. void __iomem *acpi_os_get_iomem(acpi_physical_address phys, unsigned int size)
  261. {
  262. struct acpi_ioremap *map;
  263. void __iomem *virt = NULL;
  264. mutex_lock(&acpi_ioremap_lock);
  265. map = acpi_map_lookup(phys, size);
  266. if (map) {
  267. virt = map->virt + (phys - map->phys);
  268. map->refcount++;
  269. }
  270. mutex_unlock(&acpi_ioremap_lock);
  271. return virt;
  272. }
  273. EXPORT_SYMBOL_GPL(acpi_os_get_iomem);
  274. /* Must be called with 'acpi_ioremap_lock' or RCU read lock held. */
  275. static struct acpi_ioremap *
  276. acpi_map_lookup_virt(void __iomem *virt, acpi_size size)
  277. {
  278. struct acpi_ioremap *map;
  279. list_for_each_entry_rcu(map, &acpi_ioremaps, list)
  280. if (map->virt <= virt &&
  281. virt + size <= map->virt + map->size)
  282. return map;
  283. return NULL;
  284. }
  285. #if defined(CONFIG_IA64) || defined(CONFIG_ARM64)
  286. /* ioremap will take care of cache attributes */
  287. #define should_use_kmap(pfn) 0
  288. #else
  289. #define should_use_kmap(pfn) page_is_ram(pfn)
  290. #endif
  291. static void __iomem *acpi_map(acpi_physical_address pg_off, unsigned long pg_sz)
  292. {
  293. unsigned long pfn;
  294. pfn = pg_off >> PAGE_SHIFT;
  295. if (should_use_kmap(pfn)) {
  296. if (pg_sz > PAGE_SIZE)
  297. return NULL;
  298. return (void __iomem __force *)kmap(pfn_to_page(pfn));
  299. } else
  300. return acpi_os_ioremap(pg_off, pg_sz);
  301. }
  302. static void acpi_unmap(acpi_physical_address pg_off, void __iomem *vaddr)
  303. {
  304. unsigned long pfn;
  305. pfn = pg_off >> PAGE_SHIFT;
  306. if (should_use_kmap(pfn))
  307. kunmap(pfn_to_page(pfn));
  308. else
  309. iounmap(vaddr);
  310. }
  311. /**
  312. * acpi_os_map_iomem - Get a virtual address for a given physical address range.
  313. * @phys: Start of the physical address range to map.
  314. * @size: Size of the physical address range to map.
  315. *
  316. * Look up the given physical address range in the list of existing ACPI memory
  317. * mappings. If found, get a reference to it and return a pointer to it (its
  318. * virtual address). If not found, map it, add it to that list and return a
  319. * pointer to it.
  320. *
  321. * During early init (when acpi_gbl_permanent_mmap has not been set yet) this
  322. * routine simply calls __acpi_map_table() to get the job done.
  323. */
  324. void __iomem *__init_refok
  325. acpi_os_map_iomem(acpi_physical_address phys, acpi_size size)
  326. {
  327. struct acpi_ioremap *map;
  328. void __iomem *virt;
  329. acpi_physical_address pg_off;
  330. acpi_size pg_sz;
  331. if (phys > ULONG_MAX) {
  332. printk(KERN_ERR PREFIX "Cannot map memory that high\n");
  333. return NULL;
  334. }
  335. if (!acpi_gbl_permanent_mmap)
  336. return __acpi_map_table((unsigned long)phys, size);
  337. mutex_lock(&acpi_ioremap_lock);
  338. /* Check if there's a suitable mapping already. */
  339. map = acpi_map_lookup(phys, size);
  340. if (map) {
  341. map->refcount++;
  342. goto out;
  343. }
  344. map = kzalloc(sizeof(*map), GFP_KERNEL);
  345. if (!map) {
  346. mutex_unlock(&acpi_ioremap_lock);
  347. return NULL;
  348. }
  349. pg_off = round_down(phys, PAGE_SIZE);
  350. pg_sz = round_up(phys + size, PAGE_SIZE) - pg_off;
  351. virt = acpi_map(pg_off, pg_sz);
  352. if (!virt) {
  353. mutex_unlock(&acpi_ioremap_lock);
  354. kfree(map);
  355. return NULL;
  356. }
  357. INIT_LIST_HEAD(&map->list);
  358. map->virt = virt;
  359. map->phys = pg_off;
  360. map->size = pg_sz;
  361. map->refcount = 1;
  362. list_add_tail_rcu(&map->list, &acpi_ioremaps);
  363. out:
  364. mutex_unlock(&acpi_ioremap_lock);
  365. return map->virt + (phys - map->phys);
  366. }
  367. EXPORT_SYMBOL_GPL(acpi_os_map_iomem);
  368. void *__init_refok
  369. acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
  370. {
  371. return (void *)acpi_os_map_iomem(phys, size);
  372. }
  373. EXPORT_SYMBOL_GPL(acpi_os_map_memory);
  374. static void acpi_os_drop_map_ref(struct acpi_ioremap *map)
  375. {
  376. if (!--map->refcount)
  377. list_del_rcu(&map->list);
  378. }
  379. static void acpi_os_map_cleanup(struct acpi_ioremap *map)
  380. {
  381. if (!map->refcount) {
  382. synchronize_rcu_expedited();
  383. acpi_unmap(map->phys, map->virt);
  384. kfree(map);
  385. }
  386. }
  387. /**
  388. * acpi_os_unmap_iomem - Drop a memory mapping reference.
  389. * @virt: Start of the address range to drop a reference to.
  390. * @size: Size of the address range to drop a reference to.
  391. *
  392. * Look up the given virtual address range in the list of existing ACPI memory
  393. * mappings, drop a reference to it and unmap it if there are no more active
  394. * references to it.
  395. *
  396. * During early init (when acpi_gbl_permanent_mmap has not been set yet) this
  397. * routine simply calls __acpi_unmap_table() to get the job done. Since
  398. * __acpi_unmap_table() is an __init function, the __ref annotation is needed
  399. * here.
  400. */
  401. void __ref acpi_os_unmap_iomem(void __iomem *virt, acpi_size size)
  402. {
  403. struct acpi_ioremap *map;
  404. if (!acpi_gbl_permanent_mmap) {
  405. __acpi_unmap_table(virt, size);
  406. return;
  407. }
  408. mutex_lock(&acpi_ioremap_lock);
  409. map = acpi_map_lookup_virt(virt, size);
  410. if (!map) {
  411. mutex_unlock(&acpi_ioremap_lock);
  412. WARN(true, PREFIX "%s: bad address %p\n", __func__, virt);
  413. return;
  414. }
  415. acpi_os_drop_map_ref(map);
  416. mutex_unlock(&acpi_ioremap_lock);
  417. acpi_os_map_cleanup(map);
  418. }
  419. EXPORT_SYMBOL_GPL(acpi_os_unmap_iomem);
  420. void __ref acpi_os_unmap_memory(void *virt, acpi_size size)
  421. {
  422. return acpi_os_unmap_iomem((void __iomem *)virt, size);
  423. }
  424. EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
  425. void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  426. {
  427. if (!acpi_gbl_permanent_mmap)
  428. __acpi_unmap_table(virt, size);
  429. }
  430. int acpi_os_map_generic_address(struct acpi_generic_address *gas)
  431. {
  432. u64 addr;
  433. void __iomem *virt;
  434. if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
  435. return 0;
  436. /* Handle possible alignment issues */
  437. memcpy(&addr, &gas->address, sizeof(addr));
  438. if (!addr || !gas->bit_width)
  439. return -EINVAL;
  440. virt = acpi_os_map_iomem(addr, gas->bit_width / 8);
  441. if (!virt)
  442. return -EIO;
  443. return 0;
  444. }
  445. EXPORT_SYMBOL(acpi_os_map_generic_address);
  446. void acpi_os_unmap_generic_address(struct acpi_generic_address *gas)
  447. {
  448. u64 addr;
  449. struct acpi_ioremap *map;
  450. if (gas->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY)
  451. return;
  452. /* Handle possible alignment issues */
  453. memcpy(&addr, &gas->address, sizeof(addr));
  454. if (!addr || !gas->bit_width)
  455. return;
  456. mutex_lock(&acpi_ioremap_lock);
  457. map = acpi_map_lookup(addr, gas->bit_width / 8);
  458. if (!map) {
  459. mutex_unlock(&acpi_ioremap_lock);
  460. return;
  461. }
  462. acpi_os_drop_map_ref(map);
  463. mutex_unlock(&acpi_ioremap_lock);
  464. acpi_os_map_cleanup(map);
  465. }
  466. EXPORT_SYMBOL(acpi_os_unmap_generic_address);
  467. #ifdef ACPI_FUTURE_USAGE
  468. acpi_status
  469. acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
  470. {
  471. if (!phys || !virt)
  472. return AE_BAD_PARAMETER;
  473. *phys = virt_to_phys(virt);
  474. return AE_OK;
  475. }
  476. #endif
  477. #ifdef CONFIG_ACPI_REV_OVERRIDE_POSSIBLE
  478. static bool acpi_rev_override;
  479. int __init acpi_rev_override_setup(char *str)
  480. {
  481. acpi_rev_override = true;
  482. return 1;
  483. }
  484. __setup("acpi_rev_override", acpi_rev_override_setup);
  485. #else
  486. #define acpi_rev_override false
  487. #endif
  488. #define ACPI_MAX_OVERRIDE_LEN 100
  489. static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
  490. acpi_status
  491. acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
  492. char **new_val)
  493. {
  494. if (!init_val || !new_val)
  495. return AE_BAD_PARAMETER;
  496. *new_val = NULL;
  497. if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
  498. printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
  499. acpi_os_name);
  500. *new_val = acpi_os_name;
  501. }
  502. if (!memcmp(init_val->name, "_REV", 4) && acpi_rev_override) {
  503. printk(KERN_INFO PREFIX "Overriding _REV return value to 5\n");
  504. *new_val = (char *)5;
  505. }
  506. return AE_OK;
  507. }
  508. static void acpi_table_taint(struct acpi_table_header *table)
  509. {
  510. pr_warn(PREFIX
  511. "Override [%4.4s-%8.8s], this is unsafe: tainting kernel\n",
  512. table->signature, table->oem_table_id);
  513. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
  514. }
  515. #ifdef CONFIG_ACPI_INITRD_TABLE_OVERRIDE
  516. #include <linux/earlycpio.h>
  517. #include <linux/memblock.h>
  518. static u64 acpi_tables_addr;
  519. static int all_tables_size;
  520. /* Copied from acpica/tbutils.c:acpi_tb_checksum() */
  521. static u8 __init acpi_table_checksum(u8 *buffer, u32 length)
  522. {
  523. u8 sum = 0;
  524. u8 *end = buffer + length;
  525. while (buffer < end)
  526. sum = (u8) (sum + *(buffer++));
  527. return sum;
  528. }
  529. /* All but ACPI_SIG_RSDP and ACPI_SIG_FACS: */
  530. static const char * const table_sigs[] = {
  531. ACPI_SIG_BERT, ACPI_SIG_CPEP, ACPI_SIG_ECDT, ACPI_SIG_EINJ,
  532. ACPI_SIG_ERST, ACPI_SIG_HEST, ACPI_SIG_MADT, ACPI_SIG_MSCT,
  533. ACPI_SIG_SBST, ACPI_SIG_SLIT, ACPI_SIG_SRAT, ACPI_SIG_ASF,
  534. ACPI_SIG_BOOT, ACPI_SIG_DBGP, ACPI_SIG_DMAR, ACPI_SIG_HPET,
  535. ACPI_SIG_IBFT, ACPI_SIG_IVRS, ACPI_SIG_MCFG, ACPI_SIG_MCHI,
  536. ACPI_SIG_SLIC, ACPI_SIG_SPCR, ACPI_SIG_SPMI, ACPI_SIG_TCPA,
  537. ACPI_SIG_UEFI, ACPI_SIG_WAET, ACPI_SIG_WDAT, ACPI_SIG_WDDT,
  538. ACPI_SIG_WDRT, ACPI_SIG_DSDT, ACPI_SIG_FADT, ACPI_SIG_PSDT,
  539. ACPI_SIG_RSDT, ACPI_SIG_XSDT, ACPI_SIG_SSDT, NULL };
  540. #define ACPI_HEADER_SIZE sizeof(struct acpi_table_header)
  541. #define ACPI_OVERRIDE_TABLES 64
  542. static struct cpio_data __initdata acpi_initrd_files[ACPI_OVERRIDE_TABLES];
  543. static DECLARE_BITMAP(acpi_initrd_installed, ACPI_OVERRIDE_TABLES);
  544. #define MAP_CHUNK_SIZE (NR_FIX_BTMAPS << PAGE_SHIFT)
  545. void __init acpi_initrd_override(void *data, size_t size)
  546. {
  547. int sig, no, table_nr = 0, total_offset = 0;
  548. long offset = 0;
  549. struct acpi_table_header *table;
  550. char cpio_path[32] = "kernel/firmware/acpi/";
  551. struct cpio_data file;
  552. if (data == NULL || size == 0)
  553. return;
  554. for (no = 0; no < ACPI_OVERRIDE_TABLES; no++) {
  555. file = find_cpio_data(cpio_path, data, size, &offset);
  556. if (!file.data)
  557. break;
  558. data += offset;
  559. size -= offset;
  560. if (file.size < sizeof(struct acpi_table_header)) {
  561. pr_err("ACPI OVERRIDE: Table smaller than ACPI header [%s%s]\n",
  562. cpio_path, file.name);
  563. continue;
  564. }
  565. table = file.data;
  566. for (sig = 0; table_sigs[sig]; sig++)
  567. if (!memcmp(table->signature, table_sigs[sig], 4))
  568. break;
  569. if (!table_sigs[sig]) {
  570. pr_err("ACPI OVERRIDE: Unknown signature [%s%s]\n",
  571. cpio_path, file.name);
  572. continue;
  573. }
  574. if (file.size != table->length) {
  575. pr_err("ACPI OVERRIDE: File length does not match table length [%s%s]\n",
  576. cpio_path, file.name);
  577. continue;
  578. }
  579. if (acpi_table_checksum(file.data, table->length)) {
  580. pr_err("ACPI OVERRIDE: Bad table checksum [%s%s]\n",
  581. cpio_path, file.name);
  582. continue;
  583. }
  584. pr_info("%4.4s ACPI table found in initrd [%s%s][0x%x]\n",
  585. table->signature, cpio_path, file.name, table->length);
  586. all_tables_size += table->length;
  587. acpi_initrd_files[table_nr].data = file.data;
  588. acpi_initrd_files[table_nr].size = file.size;
  589. table_nr++;
  590. }
  591. if (table_nr == 0)
  592. return;
  593. acpi_tables_addr =
  594. memblock_find_in_range(0, max_low_pfn_mapped << PAGE_SHIFT,
  595. all_tables_size, PAGE_SIZE);
  596. if (!acpi_tables_addr) {
  597. WARN_ON(1);
  598. return;
  599. }
  600. /*
  601. * Only calling e820_add_reserve does not work and the
  602. * tables are invalid (memory got used) later.
  603. * memblock_reserve works as expected and the tables won't get modified.
  604. * But it's not enough on X86 because ioremap will
  605. * complain later (used by acpi_os_map_memory) that the pages
  606. * that should get mapped are not marked "reserved".
  607. * Both memblock_reserve and e820_add_region (via arch_reserve_mem_area)
  608. * works fine.
  609. */
  610. memblock_reserve(acpi_tables_addr, all_tables_size);
  611. arch_reserve_mem_area(acpi_tables_addr, all_tables_size);
  612. /*
  613. * early_ioremap only can remap 256k one time. If we map all
  614. * tables one time, we will hit the limit. Need to map chunks
  615. * one by one during copying the same as that in relocate_initrd().
  616. */
  617. for (no = 0; no < table_nr; no++) {
  618. unsigned char *src_p = acpi_initrd_files[no].data;
  619. phys_addr_t size = acpi_initrd_files[no].size;
  620. phys_addr_t dest_addr = acpi_tables_addr + total_offset;
  621. phys_addr_t slop, clen;
  622. char *dest_p;
  623. total_offset += size;
  624. while (size) {
  625. slop = dest_addr & ~PAGE_MASK;
  626. clen = size;
  627. if (clen > MAP_CHUNK_SIZE - slop)
  628. clen = MAP_CHUNK_SIZE - slop;
  629. dest_p = early_ioremap(dest_addr & PAGE_MASK,
  630. clen + slop);
  631. memcpy(dest_p + slop, src_p, clen);
  632. early_iounmap(dest_p, clen + slop);
  633. src_p += clen;
  634. dest_addr += clen;
  635. size -= clen;
  636. }
  637. }
  638. }
  639. acpi_status
  640. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  641. acpi_physical_address *address, u32 *length)
  642. {
  643. int table_offset = 0;
  644. int table_index = 0;
  645. struct acpi_table_header *table;
  646. u32 table_length;
  647. *length = 0;
  648. *address = 0;
  649. if (!acpi_tables_addr)
  650. return AE_OK;
  651. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  652. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  653. ACPI_HEADER_SIZE);
  654. if (table_offset + table->length > all_tables_size) {
  655. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  656. WARN_ON(1);
  657. return AE_OK;
  658. }
  659. table_length = table->length;
  660. /* Only override tables matched */
  661. if (test_bit(table_index, acpi_initrd_installed) ||
  662. memcmp(existing_table->signature, table->signature, 4) ||
  663. memcmp(table->oem_table_id, existing_table->oem_table_id,
  664. ACPI_OEM_TABLE_ID_SIZE)) {
  665. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  666. goto next_table;
  667. }
  668. *length = table_length;
  669. *address = acpi_tables_addr + table_offset;
  670. acpi_table_taint(existing_table);
  671. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  672. set_bit(table_index, acpi_initrd_installed);
  673. break;
  674. next_table:
  675. table_offset += table_length;
  676. table_index++;
  677. }
  678. return AE_OK;
  679. }
  680. void __init acpi_initrd_initialize_tables(void)
  681. {
  682. int table_offset = 0;
  683. int table_index = 0;
  684. u32 table_length;
  685. struct acpi_table_header *table;
  686. if (!acpi_tables_addr)
  687. return;
  688. while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
  689. table = acpi_os_map_memory(acpi_tables_addr + table_offset,
  690. ACPI_HEADER_SIZE);
  691. if (table_offset + table->length > all_tables_size) {
  692. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  693. WARN_ON(1);
  694. return;
  695. }
  696. table_length = table->length;
  697. /* Skip RSDT/XSDT which should only be used for override */
  698. if (test_bit(table_index, acpi_initrd_installed) ||
  699. ACPI_COMPARE_NAME(table->signature, ACPI_SIG_RSDT) ||
  700. ACPI_COMPARE_NAME(table->signature, ACPI_SIG_XSDT)) {
  701. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  702. goto next_table;
  703. }
  704. acpi_table_taint(table);
  705. acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
  706. acpi_install_table(acpi_tables_addr + table_offset, TRUE);
  707. set_bit(table_index, acpi_initrd_installed);
  708. next_table:
  709. table_offset += table_length;
  710. table_index++;
  711. }
  712. }
  713. #else
  714. acpi_status
  715. acpi_os_physical_table_override(struct acpi_table_header *existing_table,
  716. acpi_physical_address *address,
  717. u32 *table_length)
  718. {
  719. *table_length = 0;
  720. *address = 0;
  721. return AE_OK;
  722. }
  723. void __init acpi_initrd_initialize_tables(void)
  724. {
  725. }
  726. #endif /* CONFIG_ACPI_INITRD_TABLE_OVERRIDE */
  727. acpi_status
  728. acpi_os_table_override(struct acpi_table_header *existing_table,
  729. struct acpi_table_header **new_table)
  730. {
  731. if (!existing_table || !new_table)
  732. return AE_BAD_PARAMETER;
  733. *new_table = NULL;
  734. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  735. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  736. *new_table = (struct acpi_table_header *)AmlCode;
  737. #endif
  738. if (*new_table != NULL)
  739. acpi_table_taint(existing_table);
  740. return AE_OK;
  741. }
  742. static irqreturn_t acpi_irq(int irq, void *dev_id)
  743. {
  744. u32 handled;
  745. handled = (*acpi_irq_handler) (acpi_irq_context);
  746. if (handled) {
  747. acpi_irq_handled++;
  748. return IRQ_HANDLED;
  749. } else {
  750. acpi_irq_not_handled++;
  751. return IRQ_NONE;
  752. }
  753. }
  754. acpi_status
  755. acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
  756. void *context)
  757. {
  758. unsigned int irq;
  759. acpi_irq_stats_init();
  760. /*
  761. * ACPI interrupts different from the SCI in our copy of the FADT are
  762. * not supported.
  763. */
  764. if (gsi != acpi_gbl_FADT.sci_interrupt)
  765. return AE_BAD_PARAMETER;
  766. if (acpi_irq_handler)
  767. return AE_ALREADY_ACQUIRED;
  768. if (acpi_gsi_to_irq(gsi, &irq) < 0) {
  769. printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
  770. gsi);
  771. return AE_OK;
  772. }
  773. acpi_irq_handler = handler;
  774. acpi_irq_context = context;
  775. if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
  776. printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
  777. acpi_irq_handler = NULL;
  778. return AE_NOT_ACQUIRED;
  779. }
  780. acpi_sci_irq = irq;
  781. return AE_OK;
  782. }
  783. acpi_status acpi_os_remove_interrupt_handler(u32 gsi, acpi_osd_handler handler)
  784. {
  785. if (gsi != acpi_gbl_FADT.sci_interrupt || !acpi_sci_irq_valid())
  786. return AE_BAD_PARAMETER;
  787. free_irq(acpi_sci_irq, acpi_irq);
  788. acpi_irq_handler = NULL;
  789. acpi_sci_irq = INVALID_ACPI_IRQ;
  790. return AE_OK;
  791. }
  792. /*
  793. * Running in interpreter thread context, safe to sleep
  794. */
  795. void acpi_os_sleep(u64 ms)
  796. {
  797. msleep(ms);
  798. }
  799. void acpi_os_stall(u32 us)
  800. {
  801. while (us) {
  802. u32 delay = 1000;
  803. if (delay > us)
  804. delay = us;
  805. udelay(delay);
  806. touch_nmi_watchdog();
  807. us -= delay;
  808. }
  809. }
  810. /*
  811. * Support ACPI 3.0 AML Timer operand
  812. * Returns 64-bit free-running, monotonically increasing timer
  813. * with 100ns granularity
  814. */
  815. u64 acpi_os_get_timer(void)
  816. {
  817. u64 time_ns = ktime_to_ns(ktime_get());
  818. do_div(time_ns, 100);
  819. return time_ns;
  820. }
  821. acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  822. {
  823. u32 dummy;
  824. if (!value)
  825. value = &dummy;
  826. *value = 0;
  827. if (width <= 8) {
  828. *(u8 *) value = inb(port);
  829. } else if (width <= 16) {
  830. *(u16 *) value = inw(port);
  831. } else if (width <= 32) {
  832. *(u32 *) value = inl(port);
  833. } else {
  834. BUG();
  835. }
  836. return AE_OK;
  837. }
  838. EXPORT_SYMBOL(acpi_os_read_port);
  839. acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  840. {
  841. if (width <= 8) {
  842. outb(value, port);
  843. } else if (width <= 16) {
  844. outw(value, port);
  845. } else if (width <= 32) {
  846. outl(value, port);
  847. } else {
  848. BUG();
  849. }
  850. return AE_OK;
  851. }
  852. EXPORT_SYMBOL(acpi_os_write_port);
  853. acpi_status
  854. acpi_os_read_memory(acpi_physical_address phys_addr, u64 *value, u32 width)
  855. {
  856. void __iomem *virt_addr;
  857. unsigned int size = width / 8;
  858. bool unmap = false;
  859. u64 dummy;
  860. rcu_read_lock();
  861. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  862. if (!virt_addr) {
  863. rcu_read_unlock();
  864. virt_addr = acpi_os_ioremap(phys_addr, size);
  865. if (!virt_addr)
  866. return AE_BAD_ADDRESS;
  867. unmap = true;
  868. }
  869. if (!value)
  870. value = &dummy;
  871. switch (width) {
  872. case 8:
  873. *(u8 *) value = readb(virt_addr);
  874. break;
  875. case 16:
  876. *(u16 *) value = readw(virt_addr);
  877. break;
  878. case 32:
  879. *(u32 *) value = readl(virt_addr);
  880. break;
  881. case 64:
  882. *(u64 *) value = readq(virt_addr);
  883. break;
  884. default:
  885. BUG();
  886. }
  887. if (unmap)
  888. iounmap(virt_addr);
  889. else
  890. rcu_read_unlock();
  891. return AE_OK;
  892. }
  893. acpi_status
  894. acpi_os_write_memory(acpi_physical_address phys_addr, u64 value, u32 width)
  895. {
  896. void __iomem *virt_addr;
  897. unsigned int size = width / 8;
  898. bool unmap = false;
  899. rcu_read_lock();
  900. virt_addr = acpi_map_vaddr_lookup(phys_addr, size);
  901. if (!virt_addr) {
  902. rcu_read_unlock();
  903. virt_addr = acpi_os_ioremap(phys_addr, size);
  904. if (!virt_addr)
  905. return AE_BAD_ADDRESS;
  906. unmap = true;
  907. }
  908. switch (width) {
  909. case 8:
  910. writeb(value, virt_addr);
  911. break;
  912. case 16:
  913. writew(value, virt_addr);
  914. break;
  915. case 32:
  916. writel(value, virt_addr);
  917. break;
  918. case 64:
  919. writeq(value, virt_addr);
  920. break;
  921. default:
  922. BUG();
  923. }
  924. if (unmap)
  925. iounmap(virt_addr);
  926. else
  927. rcu_read_unlock();
  928. return AE_OK;
  929. }
  930. acpi_status
  931. acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  932. u64 *value, u32 width)
  933. {
  934. int result, size;
  935. u32 value32;
  936. if (!value)
  937. return AE_BAD_PARAMETER;
  938. switch (width) {
  939. case 8:
  940. size = 1;
  941. break;
  942. case 16:
  943. size = 2;
  944. break;
  945. case 32:
  946. size = 4;
  947. break;
  948. default:
  949. return AE_ERROR;
  950. }
  951. result = raw_pci_read(pci_id->segment, pci_id->bus,
  952. PCI_DEVFN(pci_id->device, pci_id->function),
  953. reg, size, &value32);
  954. *value = value32;
  955. return (result ? AE_ERROR : AE_OK);
  956. }
  957. acpi_status
  958. acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  959. u64 value, u32 width)
  960. {
  961. int result, size;
  962. switch (width) {
  963. case 8:
  964. size = 1;
  965. break;
  966. case 16:
  967. size = 2;
  968. break;
  969. case 32:
  970. size = 4;
  971. break;
  972. default:
  973. return AE_ERROR;
  974. }
  975. result = raw_pci_write(pci_id->segment, pci_id->bus,
  976. PCI_DEVFN(pci_id->device, pci_id->function),
  977. reg, size, value);
  978. return (result ? AE_ERROR : AE_OK);
  979. }
  980. static void acpi_os_execute_deferred(struct work_struct *work)
  981. {
  982. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  983. dpc->function(dpc->context);
  984. kfree(dpc);
  985. }
  986. #ifdef CONFIG_ACPI_DEBUGGER
  987. static struct acpi_debugger acpi_debugger;
  988. static bool acpi_debugger_initialized;
  989. int acpi_register_debugger(struct module *owner,
  990. const struct acpi_debugger_ops *ops)
  991. {
  992. int ret = 0;
  993. mutex_lock(&acpi_debugger.lock);
  994. if (acpi_debugger.ops) {
  995. ret = -EBUSY;
  996. goto err_lock;
  997. }
  998. acpi_debugger.owner = owner;
  999. acpi_debugger.ops = ops;
  1000. err_lock:
  1001. mutex_unlock(&acpi_debugger.lock);
  1002. return ret;
  1003. }
  1004. EXPORT_SYMBOL(acpi_register_debugger);
  1005. void acpi_unregister_debugger(const struct acpi_debugger_ops *ops)
  1006. {
  1007. mutex_lock(&acpi_debugger.lock);
  1008. if (ops == acpi_debugger.ops) {
  1009. acpi_debugger.ops = NULL;
  1010. acpi_debugger.owner = NULL;
  1011. }
  1012. mutex_unlock(&acpi_debugger.lock);
  1013. }
  1014. EXPORT_SYMBOL(acpi_unregister_debugger);
  1015. int acpi_debugger_create_thread(acpi_osd_exec_callback function, void *context)
  1016. {
  1017. int ret;
  1018. int (*func)(acpi_osd_exec_callback, void *);
  1019. struct module *owner;
  1020. if (!acpi_debugger_initialized)
  1021. return -ENODEV;
  1022. mutex_lock(&acpi_debugger.lock);
  1023. if (!acpi_debugger.ops) {
  1024. ret = -ENODEV;
  1025. goto err_lock;
  1026. }
  1027. if (!try_module_get(acpi_debugger.owner)) {
  1028. ret = -ENODEV;
  1029. goto err_lock;
  1030. }
  1031. func = acpi_debugger.ops->create_thread;
  1032. owner = acpi_debugger.owner;
  1033. mutex_unlock(&acpi_debugger.lock);
  1034. ret = func(function, context);
  1035. mutex_lock(&acpi_debugger.lock);
  1036. module_put(owner);
  1037. err_lock:
  1038. mutex_unlock(&acpi_debugger.lock);
  1039. return ret;
  1040. }
  1041. ssize_t acpi_debugger_write_log(const char *msg)
  1042. {
  1043. ssize_t ret;
  1044. ssize_t (*func)(const char *);
  1045. struct module *owner;
  1046. if (!acpi_debugger_initialized)
  1047. return -ENODEV;
  1048. mutex_lock(&acpi_debugger.lock);
  1049. if (!acpi_debugger.ops) {
  1050. ret = -ENODEV;
  1051. goto err_lock;
  1052. }
  1053. if (!try_module_get(acpi_debugger.owner)) {
  1054. ret = -ENODEV;
  1055. goto err_lock;
  1056. }
  1057. func = acpi_debugger.ops->write_log;
  1058. owner = acpi_debugger.owner;
  1059. mutex_unlock(&acpi_debugger.lock);
  1060. ret = func(msg);
  1061. mutex_lock(&acpi_debugger.lock);
  1062. module_put(owner);
  1063. err_lock:
  1064. mutex_unlock(&acpi_debugger.lock);
  1065. return ret;
  1066. }
  1067. ssize_t acpi_debugger_read_cmd(char *buffer, size_t buffer_length)
  1068. {
  1069. ssize_t ret;
  1070. ssize_t (*func)(char *, size_t);
  1071. struct module *owner;
  1072. if (!acpi_debugger_initialized)
  1073. return -ENODEV;
  1074. mutex_lock(&acpi_debugger.lock);
  1075. if (!acpi_debugger.ops) {
  1076. ret = -ENODEV;
  1077. goto err_lock;
  1078. }
  1079. if (!try_module_get(acpi_debugger.owner)) {
  1080. ret = -ENODEV;
  1081. goto err_lock;
  1082. }
  1083. func = acpi_debugger.ops->read_cmd;
  1084. owner = acpi_debugger.owner;
  1085. mutex_unlock(&acpi_debugger.lock);
  1086. ret = func(buffer, buffer_length);
  1087. mutex_lock(&acpi_debugger.lock);
  1088. module_put(owner);
  1089. err_lock:
  1090. mutex_unlock(&acpi_debugger.lock);
  1091. return ret;
  1092. }
  1093. int acpi_debugger_wait_command_ready(void)
  1094. {
  1095. int ret;
  1096. int (*func)(bool, char *, size_t);
  1097. struct module *owner;
  1098. if (!acpi_debugger_initialized)
  1099. return -ENODEV;
  1100. mutex_lock(&acpi_debugger.lock);
  1101. if (!acpi_debugger.ops) {
  1102. ret = -ENODEV;
  1103. goto err_lock;
  1104. }
  1105. if (!try_module_get(acpi_debugger.owner)) {
  1106. ret = -ENODEV;
  1107. goto err_lock;
  1108. }
  1109. func = acpi_debugger.ops->wait_command_ready;
  1110. owner = acpi_debugger.owner;
  1111. mutex_unlock(&acpi_debugger.lock);
  1112. ret = func(acpi_gbl_method_executing,
  1113. acpi_gbl_db_line_buf, ACPI_DB_LINE_BUFFER_SIZE);
  1114. mutex_lock(&acpi_debugger.lock);
  1115. module_put(owner);
  1116. err_lock:
  1117. mutex_unlock(&acpi_debugger.lock);
  1118. return ret;
  1119. }
  1120. int acpi_debugger_notify_command_complete(void)
  1121. {
  1122. int ret;
  1123. int (*func)(void);
  1124. struct module *owner;
  1125. if (!acpi_debugger_initialized)
  1126. return -ENODEV;
  1127. mutex_lock(&acpi_debugger.lock);
  1128. if (!acpi_debugger.ops) {
  1129. ret = -ENODEV;
  1130. goto err_lock;
  1131. }
  1132. if (!try_module_get(acpi_debugger.owner)) {
  1133. ret = -ENODEV;
  1134. goto err_lock;
  1135. }
  1136. func = acpi_debugger.ops->notify_command_complete;
  1137. owner = acpi_debugger.owner;
  1138. mutex_unlock(&acpi_debugger.lock);
  1139. ret = func();
  1140. mutex_lock(&acpi_debugger.lock);
  1141. module_put(owner);
  1142. err_lock:
  1143. mutex_unlock(&acpi_debugger.lock);
  1144. return ret;
  1145. }
  1146. int __init acpi_debugger_init(void)
  1147. {
  1148. mutex_init(&acpi_debugger.lock);
  1149. acpi_debugger_initialized = true;
  1150. return 0;
  1151. }
  1152. #endif
  1153. /*******************************************************************************
  1154. *
  1155. * FUNCTION: acpi_os_execute
  1156. *
  1157. * PARAMETERS: Type - Type of the callback
  1158. * Function - Function to be executed
  1159. * Context - Function parameters
  1160. *
  1161. * RETURN: Status
  1162. *
  1163. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  1164. * immediately executes function on a separate thread.
  1165. *
  1166. ******************************************************************************/
  1167. acpi_status acpi_os_execute(acpi_execute_type type,
  1168. acpi_osd_exec_callback function, void *context)
  1169. {
  1170. acpi_status status = AE_OK;
  1171. struct acpi_os_dpc *dpc;
  1172. struct workqueue_struct *queue;
  1173. int ret;
  1174. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  1175. "Scheduling function [%p(%p)] for deferred execution.\n",
  1176. function, context));
  1177. if (type == OSL_DEBUGGER_MAIN_THREAD) {
  1178. ret = acpi_debugger_create_thread(function, context);
  1179. if (ret) {
  1180. pr_err("Call to kthread_create() failed.\n");
  1181. status = AE_ERROR;
  1182. }
  1183. goto out_thread;
  1184. }
  1185. /*
  1186. * Allocate/initialize DPC structure. Note that this memory will be
  1187. * freed by the callee. The kernel handles the work_struct list in a
  1188. * way that allows us to also free its memory inside the callee.
  1189. * Because we may want to schedule several tasks with different
  1190. * parameters we can't use the approach some kernel code uses of
  1191. * having a static work_struct.
  1192. */
  1193. dpc = kzalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  1194. if (!dpc)
  1195. return AE_NO_MEMORY;
  1196. dpc->function = function;
  1197. dpc->context = context;
  1198. /*
  1199. * To prevent lockdep from complaining unnecessarily, make sure that
  1200. * there is a different static lockdep key for each workqueue by using
  1201. * INIT_WORK() for each of them separately.
  1202. */
  1203. if (type == OSL_NOTIFY_HANDLER) {
  1204. queue = kacpi_notify_wq;
  1205. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  1206. } else if (type == OSL_GPE_HANDLER) {
  1207. queue = kacpid_wq;
  1208. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  1209. } else {
  1210. pr_err("Unsupported os_execute type %d.\n", type);
  1211. status = AE_ERROR;
  1212. }
  1213. if (ACPI_FAILURE(status))
  1214. goto err_workqueue;
  1215. /*
  1216. * On some machines, a software-initiated SMI causes corruption unless
  1217. * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
  1218. * typically it's done in GPE-related methods that are run via
  1219. * workqueues, so we can avoid the known corruption cases by always
  1220. * queueing on CPU 0.
  1221. */
  1222. ret = queue_work_on(0, queue, &dpc->work);
  1223. if (!ret) {
  1224. printk(KERN_ERR PREFIX
  1225. "Call to queue_work() failed.\n");
  1226. status = AE_ERROR;
  1227. }
  1228. err_workqueue:
  1229. if (ACPI_FAILURE(status))
  1230. kfree(dpc);
  1231. out_thread:
  1232. return status;
  1233. }
  1234. EXPORT_SYMBOL(acpi_os_execute);
  1235. void acpi_os_wait_events_complete(void)
  1236. {
  1237. /*
  1238. * Make sure the GPE handler or the fixed event handler is not used
  1239. * on another CPU after removal.
  1240. */
  1241. if (acpi_sci_irq_valid())
  1242. synchronize_hardirq(acpi_sci_irq);
  1243. flush_workqueue(kacpid_wq);
  1244. flush_workqueue(kacpi_notify_wq);
  1245. }
  1246. struct acpi_hp_work {
  1247. struct work_struct work;
  1248. struct acpi_device *adev;
  1249. u32 src;
  1250. };
  1251. static void acpi_hotplug_work_fn(struct work_struct *work)
  1252. {
  1253. struct acpi_hp_work *hpw = container_of(work, struct acpi_hp_work, work);
  1254. acpi_os_wait_events_complete();
  1255. acpi_device_hotplug(hpw->adev, hpw->src);
  1256. kfree(hpw);
  1257. }
  1258. acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src)
  1259. {
  1260. struct acpi_hp_work *hpw;
  1261. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  1262. "Scheduling hotplug event (%p, %u) for deferred execution.\n",
  1263. adev, src));
  1264. hpw = kmalloc(sizeof(*hpw), GFP_KERNEL);
  1265. if (!hpw)
  1266. return AE_NO_MEMORY;
  1267. INIT_WORK(&hpw->work, acpi_hotplug_work_fn);
  1268. hpw->adev = adev;
  1269. hpw->src = src;
  1270. /*
  1271. * We can't run hotplug code in kacpid_wq/kacpid_notify_wq etc., because
  1272. * the hotplug code may call driver .remove() functions, which may
  1273. * invoke flush_scheduled_work()/acpi_os_wait_events_complete() to flush
  1274. * these workqueues.
  1275. */
  1276. if (!queue_work(kacpi_hotplug_wq, &hpw->work)) {
  1277. kfree(hpw);
  1278. return AE_ERROR;
  1279. }
  1280. return AE_OK;
  1281. }
  1282. bool acpi_queue_hotplug_work(struct work_struct *work)
  1283. {
  1284. return queue_work(kacpi_hotplug_wq, work);
  1285. }
  1286. acpi_status
  1287. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  1288. {
  1289. struct semaphore *sem = NULL;
  1290. sem = acpi_os_allocate_zeroed(sizeof(struct semaphore));
  1291. if (!sem)
  1292. return AE_NO_MEMORY;
  1293. sema_init(sem, initial_units);
  1294. *handle = (acpi_handle *) sem;
  1295. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  1296. *handle, initial_units));
  1297. return AE_OK;
  1298. }
  1299. /*
  1300. * TODO: A better way to delete semaphores? Linux doesn't have a
  1301. * 'delete_semaphore()' function -- may result in an invalid
  1302. * pointer dereference for non-synchronized consumers. Should
  1303. * we at least check for blocked threads and signal/cancel them?
  1304. */
  1305. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  1306. {
  1307. struct semaphore *sem = (struct semaphore *)handle;
  1308. if (!sem)
  1309. return AE_BAD_PARAMETER;
  1310. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  1311. BUG_ON(!list_empty(&sem->wait_list));
  1312. kfree(sem);
  1313. sem = NULL;
  1314. return AE_OK;
  1315. }
  1316. /*
  1317. * TODO: Support for units > 1?
  1318. */
  1319. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  1320. {
  1321. acpi_status status = AE_OK;
  1322. struct semaphore *sem = (struct semaphore *)handle;
  1323. long jiffies;
  1324. int ret = 0;
  1325. if (!acpi_os_initialized)
  1326. return AE_OK;
  1327. if (!sem || (units < 1))
  1328. return AE_BAD_PARAMETER;
  1329. if (units > 1)
  1330. return AE_SUPPORT;
  1331. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  1332. handle, units, timeout));
  1333. if (timeout == ACPI_WAIT_FOREVER)
  1334. jiffies = MAX_SCHEDULE_TIMEOUT;
  1335. else
  1336. jiffies = msecs_to_jiffies(timeout);
  1337. ret = down_timeout(sem, jiffies);
  1338. if (ret)
  1339. status = AE_TIME;
  1340. if (ACPI_FAILURE(status)) {
  1341. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  1342. "Failed to acquire semaphore[%p|%d|%d], %s",
  1343. handle, units, timeout,
  1344. acpi_format_exception(status)));
  1345. } else {
  1346. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  1347. "Acquired semaphore[%p|%d|%d]", handle,
  1348. units, timeout));
  1349. }
  1350. return status;
  1351. }
  1352. /*
  1353. * TODO: Support for units > 1?
  1354. */
  1355. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  1356. {
  1357. struct semaphore *sem = (struct semaphore *)handle;
  1358. if (!acpi_os_initialized)
  1359. return AE_OK;
  1360. if (!sem || (units < 1))
  1361. return AE_BAD_PARAMETER;
  1362. if (units > 1)
  1363. return AE_SUPPORT;
  1364. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  1365. units));
  1366. up(sem);
  1367. return AE_OK;
  1368. }
  1369. acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
  1370. {
  1371. #ifdef ENABLE_DEBUGGER
  1372. if (acpi_in_debugger) {
  1373. u32 chars;
  1374. kdb_read(buffer, buffer_length);
  1375. /* remove the CR kdb includes */
  1376. chars = strlen(buffer) - 1;
  1377. buffer[chars] = '\0';
  1378. }
  1379. #else
  1380. int ret;
  1381. ret = acpi_debugger_read_cmd(buffer, buffer_length);
  1382. if (ret < 0)
  1383. return AE_ERROR;
  1384. if (bytes_read)
  1385. *bytes_read = ret;
  1386. #endif
  1387. return AE_OK;
  1388. }
  1389. EXPORT_SYMBOL(acpi_os_get_line);
  1390. acpi_status acpi_os_wait_command_ready(void)
  1391. {
  1392. int ret;
  1393. ret = acpi_debugger_wait_command_ready();
  1394. if (ret < 0)
  1395. return AE_ERROR;
  1396. return AE_OK;
  1397. }
  1398. acpi_status acpi_os_notify_command_complete(void)
  1399. {
  1400. int ret;
  1401. ret = acpi_debugger_notify_command_complete();
  1402. if (ret < 0)
  1403. return AE_ERROR;
  1404. return AE_OK;
  1405. }
  1406. acpi_status acpi_os_signal(u32 function, void *info)
  1407. {
  1408. switch (function) {
  1409. case ACPI_SIGNAL_FATAL:
  1410. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  1411. break;
  1412. case ACPI_SIGNAL_BREAKPOINT:
  1413. /*
  1414. * AML Breakpoint
  1415. * ACPI spec. says to treat it as a NOP unless
  1416. * you are debugging. So if/when we integrate
  1417. * AML debugger into the kernel debugger its
  1418. * hook will go here. But until then it is
  1419. * not useful to print anything on breakpoints.
  1420. */
  1421. break;
  1422. default:
  1423. break;
  1424. }
  1425. return AE_OK;
  1426. }
  1427. static int __init acpi_os_name_setup(char *str)
  1428. {
  1429. char *p = acpi_os_name;
  1430. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  1431. if (!str || !*str)
  1432. return 0;
  1433. for (; count-- && *str; str++) {
  1434. if (isalnum(*str) || *str == ' ' || *str == ':')
  1435. *p++ = *str;
  1436. else if (*str == '\'' || *str == '"')
  1437. continue;
  1438. else
  1439. break;
  1440. }
  1441. *p = 0;
  1442. return 1;
  1443. }
  1444. __setup("acpi_os_name=", acpi_os_name_setup);
  1445. #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
  1446. #define OSI_STRING_ENTRIES_MAX 16 /* arbitrary */
  1447. struct osi_setup_entry {
  1448. char string[OSI_STRING_LENGTH_MAX];
  1449. bool enable;
  1450. };
  1451. static struct osi_setup_entry
  1452. osi_setup_entries[OSI_STRING_ENTRIES_MAX] __initdata = {
  1453. {"Module Device", true},
  1454. {"Processor Device", true},
  1455. {"3.0 _SCP Extensions", true},
  1456. {"Processor Aggregator Device", true},
  1457. };
  1458. void __init acpi_osi_setup(char *str)
  1459. {
  1460. struct osi_setup_entry *osi;
  1461. bool enable = true;
  1462. int i;
  1463. if (!acpi_gbl_create_osi_method)
  1464. return;
  1465. if (str == NULL || *str == '\0') {
  1466. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  1467. acpi_gbl_create_osi_method = FALSE;
  1468. return;
  1469. }
  1470. if (*str == '!') {
  1471. str++;
  1472. if (*str == '\0') {
  1473. osi_linux.default_disabling = 1;
  1474. return;
  1475. } else if (*str == '*') {
  1476. acpi_update_interfaces(ACPI_DISABLE_ALL_STRINGS);
  1477. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1478. osi = &osi_setup_entries[i];
  1479. osi->enable = false;
  1480. }
  1481. return;
  1482. }
  1483. enable = false;
  1484. }
  1485. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1486. osi = &osi_setup_entries[i];
  1487. if (!strcmp(osi->string, str)) {
  1488. osi->enable = enable;
  1489. break;
  1490. } else if (osi->string[0] == '\0') {
  1491. osi->enable = enable;
  1492. strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
  1493. break;
  1494. }
  1495. }
  1496. }
  1497. static void __init set_osi_linux(unsigned int enable)
  1498. {
  1499. if (osi_linux.enable != enable)
  1500. osi_linux.enable = enable;
  1501. if (osi_linux.enable)
  1502. acpi_osi_setup("Linux");
  1503. else
  1504. acpi_osi_setup("!Linux");
  1505. return;
  1506. }
  1507. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  1508. {
  1509. osi_linux.cmdline = 1; /* cmdline set the default and override DMI */
  1510. osi_linux.dmi = 0;
  1511. set_osi_linux(enable);
  1512. return;
  1513. }
  1514. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  1515. {
  1516. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  1517. if (enable == -1)
  1518. return;
  1519. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  1520. set_osi_linux(enable);
  1521. return;
  1522. }
  1523. /*
  1524. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  1525. *
  1526. * empty string disables _OSI
  1527. * string starting with '!' disables that string
  1528. * otherwise string is added to list, augmenting built-in strings
  1529. */
  1530. static void __init acpi_osi_setup_late(void)
  1531. {
  1532. struct osi_setup_entry *osi;
  1533. char *str;
  1534. int i;
  1535. acpi_status status;
  1536. if (osi_linux.default_disabling) {
  1537. status = acpi_update_interfaces(ACPI_DISABLE_ALL_VENDOR_STRINGS);
  1538. if (ACPI_SUCCESS(status))
  1539. printk(KERN_INFO PREFIX "Disabled all _OSI OS vendors\n");
  1540. }
  1541. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1542. osi = &osi_setup_entries[i];
  1543. str = osi->string;
  1544. if (*str == '\0')
  1545. break;
  1546. if (osi->enable) {
  1547. status = acpi_install_interface(str);
  1548. if (ACPI_SUCCESS(status))
  1549. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  1550. } else {
  1551. status = acpi_remove_interface(str);
  1552. if (ACPI_SUCCESS(status))
  1553. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  1554. }
  1555. }
  1556. }
  1557. static int __init osi_setup(char *str)
  1558. {
  1559. if (str && !strcmp("Linux", str))
  1560. acpi_cmdline_osi_linux(1);
  1561. else if (str && !strcmp("!Linux", str))
  1562. acpi_cmdline_osi_linux(0);
  1563. else
  1564. acpi_osi_setup(str);
  1565. return 1;
  1566. }
  1567. __setup("acpi_osi=", osi_setup);
  1568. /*
  1569. * Disable the auto-serialization of named objects creation methods.
  1570. *
  1571. * This feature is enabled by default. It marks the AML control methods
  1572. * that contain the opcodes to create named objects as "Serialized".
  1573. */
  1574. static int __init acpi_no_auto_serialize_setup(char *str)
  1575. {
  1576. acpi_gbl_auto_serialize_methods = FALSE;
  1577. pr_info("ACPI: auto-serialization disabled\n");
  1578. return 1;
  1579. }
  1580. __setup("acpi_no_auto_serialize", acpi_no_auto_serialize_setup);
  1581. /* Check of resource interference between native drivers and ACPI
  1582. * OperationRegions (SystemIO and System Memory only).
  1583. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  1584. * in arbitrary AML code and can interfere with legacy drivers.
  1585. * acpi_enforce_resources= can be set to:
  1586. *
  1587. * - strict (default) (2)
  1588. * -> further driver trying to access the resources will not load
  1589. * - lax (1)
  1590. * -> further driver trying to access the resources will load, but you
  1591. * get a system message that something might go wrong...
  1592. *
  1593. * - no (0)
  1594. * -> ACPI Operation Region resources will not be registered
  1595. *
  1596. */
  1597. #define ENFORCE_RESOURCES_STRICT 2
  1598. #define ENFORCE_RESOURCES_LAX 1
  1599. #define ENFORCE_RESOURCES_NO 0
  1600. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1601. static int __init acpi_enforce_resources_setup(char *str)
  1602. {
  1603. if (str == NULL || *str == '\0')
  1604. return 0;
  1605. if (!strcmp("strict", str))
  1606. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1607. else if (!strcmp("lax", str))
  1608. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  1609. else if (!strcmp("no", str))
  1610. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  1611. return 1;
  1612. }
  1613. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  1614. /* Check for resource conflicts between ACPI OperationRegions and native
  1615. * drivers */
  1616. int acpi_check_resource_conflict(const struct resource *res)
  1617. {
  1618. acpi_adr_space_type space_id;
  1619. acpi_size length;
  1620. u8 warn = 0;
  1621. int clash = 0;
  1622. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1623. return 0;
  1624. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  1625. return 0;
  1626. if (res->flags & IORESOURCE_IO)
  1627. space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  1628. else
  1629. space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  1630. length = resource_size(res);
  1631. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
  1632. warn = 1;
  1633. clash = acpi_check_address_range(space_id, res->start, length, warn);
  1634. if (clash) {
  1635. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  1636. if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
  1637. printk(KERN_NOTICE "ACPI: This conflict may"
  1638. " cause random problems and system"
  1639. " instability\n");
  1640. printk(KERN_INFO "ACPI: If an ACPI driver is available"
  1641. " for this device, you should use it instead of"
  1642. " the native driver\n");
  1643. }
  1644. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  1645. return -EBUSY;
  1646. }
  1647. return 0;
  1648. }
  1649. EXPORT_SYMBOL(acpi_check_resource_conflict);
  1650. int acpi_check_region(resource_size_t start, resource_size_t n,
  1651. const char *name)
  1652. {
  1653. struct resource res = {
  1654. .start = start,
  1655. .end = start + n - 1,
  1656. .name = name,
  1657. .flags = IORESOURCE_IO,
  1658. };
  1659. return acpi_check_resource_conflict(&res);
  1660. }
  1661. EXPORT_SYMBOL(acpi_check_region);
  1662. /*
  1663. * Let drivers know whether the resource checks are effective
  1664. */
  1665. int acpi_resources_are_enforced(void)
  1666. {
  1667. return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
  1668. }
  1669. EXPORT_SYMBOL(acpi_resources_are_enforced);
  1670. bool acpi_osi_is_win8(void)
  1671. {
  1672. return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
  1673. }
  1674. EXPORT_SYMBOL(acpi_osi_is_win8);
  1675. /*
  1676. * Deallocate the memory for a spinlock.
  1677. */
  1678. void acpi_os_delete_lock(acpi_spinlock handle)
  1679. {
  1680. ACPI_FREE(handle);
  1681. }
  1682. /*
  1683. * Acquire a spinlock.
  1684. *
  1685. * handle is a pointer to the spinlock_t.
  1686. */
  1687. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1688. {
  1689. acpi_cpu_flags flags;
  1690. spin_lock_irqsave(lockp, flags);
  1691. return flags;
  1692. }
  1693. /*
  1694. * Release a spinlock. See above.
  1695. */
  1696. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1697. {
  1698. spin_unlock_irqrestore(lockp, flags);
  1699. }
  1700. #ifndef ACPI_USE_LOCAL_CACHE
  1701. /*******************************************************************************
  1702. *
  1703. * FUNCTION: acpi_os_create_cache
  1704. *
  1705. * PARAMETERS: name - Ascii name for the cache
  1706. * size - Size of each cached object
  1707. * depth - Maximum depth of the cache (in objects) <ignored>
  1708. * cache - Where the new cache object is returned
  1709. *
  1710. * RETURN: status
  1711. *
  1712. * DESCRIPTION: Create a cache object
  1713. *
  1714. ******************************************************************************/
  1715. acpi_status
  1716. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1717. {
  1718. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1719. if (*cache == NULL)
  1720. return AE_ERROR;
  1721. else
  1722. return AE_OK;
  1723. }
  1724. /*******************************************************************************
  1725. *
  1726. * FUNCTION: acpi_os_purge_cache
  1727. *
  1728. * PARAMETERS: Cache - Handle to cache object
  1729. *
  1730. * RETURN: Status
  1731. *
  1732. * DESCRIPTION: Free all objects within the requested cache.
  1733. *
  1734. ******************************************************************************/
  1735. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1736. {
  1737. kmem_cache_shrink(cache);
  1738. return (AE_OK);
  1739. }
  1740. /*******************************************************************************
  1741. *
  1742. * FUNCTION: acpi_os_delete_cache
  1743. *
  1744. * PARAMETERS: Cache - Handle to cache object
  1745. *
  1746. * RETURN: Status
  1747. *
  1748. * DESCRIPTION: Free all objects within the requested cache and delete the
  1749. * cache object.
  1750. *
  1751. ******************************************************************************/
  1752. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1753. {
  1754. kmem_cache_destroy(cache);
  1755. return (AE_OK);
  1756. }
  1757. /*******************************************************************************
  1758. *
  1759. * FUNCTION: acpi_os_release_object
  1760. *
  1761. * PARAMETERS: Cache - Handle to cache object
  1762. * Object - The object to be released
  1763. *
  1764. * RETURN: None
  1765. *
  1766. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1767. * the object is deleted.
  1768. *
  1769. ******************************************************************************/
  1770. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1771. {
  1772. kmem_cache_free(cache, object);
  1773. return (AE_OK);
  1774. }
  1775. #endif
  1776. static int __init acpi_no_static_ssdt_setup(char *s)
  1777. {
  1778. acpi_gbl_disable_ssdt_table_install = TRUE;
  1779. pr_info("ACPI: static SSDT installation disabled\n");
  1780. return 0;
  1781. }
  1782. early_param("acpi_no_static_ssdt", acpi_no_static_ssdt_setup);
  1783. static int __init acpi_disable_return_repair(char *s)
  1784. {
  1785. printk(KERN_NOTICE PREFIX
  1786. "ACPI: Predefined validation mechanism disabled\n");
  1787. acpi_gbl_disable_auto_repair = TRUE;
  1788. return 1;
  1789. }
  1790. __setup("acpica_no_return_repair", acpi_disable_return_repair);
  1791. acpi_status __init acpi_os_initialize(void)
  1792. {
  1793. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1794. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1795. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1796. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1797. if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) {
  1798. /*
  1799. * Use acpi_os_map_generic_address to pre-map the reset
  1800. * register if it's in system memory.
  1801. */
  1802. int rv;
  1803. rv = acpi_os_map_generic_address(&acpi_gbl_FADT.reset_register);
  1804. pr_debug(PREFIX "%s: map reset_reg status %d\n", __func__, rv);
  1805. }
  1806. acpi_os_initialized = true;
  1807. return AE_OK;
  1808. }
  1809. acpi_status __init acpi_os_initialize1(void)
  1810. {
  1811. kacpid_wq = alloc_workqueue("kacpid", 0, 1);
  1812. kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
  1813. kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0);
  1814. BUG_ON(!kacpid_wq);
  1815. BUG_ON(!kacpi_notify_wq);
  1816. BUG_ON(!kacpi_hotplug_wq);
  1817. acpi_install_interface_handler(acpi_osi_handler);
  1818. acpi_osi_setup_late();
  1819. return AE_OK;
  1820. }
  1821. acpi_status acpi_os_terminate(void)
  1822. {
  1823. if (acpi_irq_handler) {
  1824. acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
  1825. acpi_irq_handler);
  1826. }
  1827. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1828. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1829. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1830. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1831. if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)
  1832. acpi_os_unmap_generic_address(&acpi_gbl_FADT.reset_register);
  1833. destroy_workqueue(kacpid_wq);
  1834. destroy_workqueue(kacpi_notify_wq);
  1835. destroy_workqueue(kacpi_hotplug_wq);
  1836. return AE_OK;
  1837. }
  1838. acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
  1839. u32 pm1b_control)
  1840. {
  1841. int rc = 0;
  1842. if (__acpi_os_prepare_sleep)
  1843. rc = __acpi_os_prepare_sleep(sleep_state,
  1844. pm1a_control, pm1b_control);
  1845. if (rc < 0)
  1846. return AE_ERROR;
  1847. else if (rc > 0)
  1848. return AE_CTRL_SKIP;
  1849. return AE_OK;
  1850. }
  1851. void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
  1852. u32 pm1a_ctrl, u32 pm1b_ctrl))
  1853. {
  1854. __acpi_os_prepare_sleep = func;
  1855. }
  1856. acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a,
  1857. u32 val_b)
  1858. {
  1859. int rc = 0;
  1860. if (__acpi_os_prepare_extended_sleep)
  1861. rc = __acpi_os_prepare_extended_sleep(sleep_state,
  1862. val_a, val_b);
  1863. if (rc < 0)
  1864. return AE_ERROR;
  1865. else if (rc > 0)
  1866. return AE_CTRL_SKIP;
  1867. return AE_OK;
  1868. }
  1869. void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
  1870. u32 val_a, u32 val_b))
  1871. {
  1872. __acpi_os_prepare_extended_sleep = func;
  1873. }