osl.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237
  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 acpi_osi_config {
  120. unsigned int linux_enable:1;
  121. unsigned int linux_dmi:1;
  122. unsigned int linux_cmdline:1;
  123. u8 default_disabling;
  124. } osi_config = {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_config.linux_enable ? "honored" : "ignored",
  131. osi_config.linux_cmdline ? " via cmdline" :
  132. osi_config.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. /* Do not override acpi_osi=!* */
  1474. if (!osi_config.default_disabling)
  1475. osi_config.default_disabling =
  1476. ACPI_DISABLE_ALL_VENDOR_STRINGS;
  1477. return;
  1478. } else if (*str == '*') {
  1479. osi_config.default_disabling = ACPI_DISABLE_ALL_STRINGS;
  1480. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1481. osi = &osi_setup_entries[i];
  1482. osi->enable = false;
  1483. }
  1484. return;
  1485. } else if (*str == '!') {
  1486. osi_config.default_disabling = 0;
  1487. return;
  1488. }
  1489. enable = false;
  1490. }
  1491. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1492. osi = &osi_setup_entries[i];
  1493. if (!strcmp(osi->string, str)) {
  1494. osi->enable = enable;
  1495. break;
  1496. } else if (osi->string[0] == '\0') {
  1497. osi->enable = enable;
  1498. strncpy(osi->string, str, OSI_STRING_LENGTH_MAX);
  1499. break;
  1500. }
  1501. }
  1502. }
  1503. static void __init set_osi_linux(unsigned int enable)
  1504. {
  1505. if (osi_config.linux_enable != enable)
  1506. osi_config.linux_enable = enable;
  1507. if (osi_config.linux_enable)
  1508. acpi_osi_setup("Linux");
  1509. else
  1510. acpi_osi_setup("!Linux");
  1511. return;
  1512. }
  1513. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  1514. {
  1515. /* cmdline set the default and override DMI */
  1516. osi_config.linux_cmdline = 1;
  1517. osi_config.linux_dmi = 0;
  1518. set_osi_linux(enable);
  1519. return;
  1520. }
  1521. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  1522. {
  1523. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  1524. if (enable == -1)
  1525. return;
  1526. /* DMI knows that this box asks OSI(Linux) */
  1527. osi_config.linux_dmi = 1;
  1528. set_osi_linux(enable);
  1529. return;
  1530. }
  1531. /*
  1532. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  1533. *
  1534. * empty string disables _OSI
  1535. * string starting with '!' disables that string
  1536. * otherwise string is added to list, augmenting built-in strings
  1537. */
  1538. static void __init acpi_osi_setup_late(void)
  1539. {
  1540. struct osi_setup_entry *osi;
  1541. char *str;
  1542. int i;
  1543. acpi_status status;
  1544. if (osi_config.default_disabling) {
  1545. status = acpi_update_interfaces(osi_config.default_disabling);
  1546. if (ACPI_SUCCESS(status))
  1547. printk(KERN_INFO PREFIX "Disabled all _OSI OS vendors%s\n",
  1548. osi_config.default_disabling ==
  1549. ACPI_DISABLE_ALL_STRINGS ?
  1550. " and feature groups" : "");
  1551. }
  1552. for (i = 0; i < OSI_STRING_ENTRIES_MAX; i++) {
  1553. osi = &osi_setup_entries[i];
  1554. str = osi->string;
  1555. if (*str == '\0')
  1556. break;
  1557. if (osi->enable) {
  1558. status = acpi_install_interface(str);
  1559. if (ACPI_SUCCESS(status))
  1560. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  1561. } else {
  1562. status = acpi_remove_interface(str);
  1563. if (ACPI_SUCCESS(status))
  1564. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  1565. }
  1566. }
  1567. }
  1568. static int __init osi_setup(char *str)
  1569. {
  1570. if (str && !strcmp("Linux", str))
  1571. acpi_cmdline_osi_linux(1);
  1572. else if (str && !strcmp("!Linux", str))
  1573. acpi_cmdline_osi_linux(0);
  1574. else
  1575. acpi_osi_setup(str);
  1576. return 1;
  1577. }
  1578. __setup("acpi_osi=", osi_setup);
  1579. /*
  1580. * Disable the auto-serialization of named objects creation methods.
  1581. *
  1582. * This feature is enabled by default. It marks the AML control methods
  1583. * that contain the opcodes to create named objects as "Serialized".
  1584. */
  1585. static int __init acpi_no_auto_serialize_setup(char *str)
  1586. {
  1587. acpi_gbl_auto_serialize_methods = FALSE;
  1588. pr_info("ACPI: auto-serialization disabled\n");
  1589. return 1;
  1590. }
  1591. __setup("acpi_no_auto_serialize", acpi_no_auto_serialize_setup);
  1592. /* Check of resource interference between native drivers and ACPI
  1593. * OperationRegions (SystemIO and System Memory only).
  1594. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  1595. * in arbitrary AML code and can interfere with legacy drivers.
  1596. * acpi_enforce_resources= can be set to:
  1597. *
  1598. * - strict (default) (2)
  1599. * -> further driver trying to access the resources will not load
  1600. * - lax (1)
  1601. * -> further driver trying to access the resources will load, but you
  1602. * get a system message that something might go wrong...
  1603. *
  1604. * - no (0)
  1605. * -> ACPI Operation Region resources will not be registered
  1606. *
  1607. */
  1608. #define ENFORCE_RESOURCES_STRICT 2
  1609. #define ENFORCE_RESOURCES_LAX 1
  1610. #define ENFORCE_RESOURCES_NO 0
  1611. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1612. static int __init acpi_enforce_resources_setup(char *str)
  1613. {
  1614. if (str == NULL || *str == '\0')
  1615. return 0;
  1616. if (!strcmp("strict", str))
  1617. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  1618. else if (!strcmp("lax", str))
  1619. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  1620. else if (!strcmp("no", str))
  1621. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  1622. return 1;
  1623. }
  1624. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  1625. /* Check for resource conflicts between ACPI OperationRegions and native
  1626. * drivers */
  1627. int acpi_check_resource_conflict(const struct resource *res)
  1628. {
  1629. acpi_adr_space_type space_id;
  1630. acpi_size length;
  1631. u8 warn = 0;
  1632. int clash = 0;
  1633. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1634. return 0;
  1635. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  1636. return 0;
  1637. if (res->flags & IORESOURCE_IO)
  1638. space_id = ACPI_ADR_SPACE_SYSTEM_IO;
  1639. else
  1640. space_id = ACPI_ADR_SPACE_SYSTEM_MEMORY;
  1641. length = resource_size(res);
  1642. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO)
  1643. warn = 1;
  1644. clash = acpi_check_address_range(space_id, res->start, length, warn);
  1645. if (clash) {
  1646. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  1647. if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
  1648. printk(KERN_NOTICE "ACPI: This conflict may"
  1649. " cause random problems and system"
  1650. " instability\n");
  1651. printk(KERN_INFO "ACPI: If an ACPI driver is available"
  1652. " for this device, you should use it instead of"
  1653. " the native driver\n");
  1654. }
  1655. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  1656. return -EBUSY;
  1657. }
  1658. return 0;
  1659. }
  1660. EXPORT_SYMBOL(acpi_check_resource_conflict);
  1661. int acpi_check_region(resource_size_t start, resource_size_t n,
  1662. const char *name)
  1663. {
  1664. struct resource res = {
  1665. .start = start,
  1666. .end = start + n - 1,
  1667. .name = name,
  1668. .flags = IORESOURCE_IO,
  1669. };
  1670. return acpi_check_resource_conflict(&res);
  1671. }
  1672. EXPORT_SYMBOL(acpi_check_region);
  1673. /*
  1674. * Let drivers know whether the resource checks are effective
  1675. */
  1676. int acpi_resources_are_enforced(void)
  1677. {
  1678. return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
  1679. }
  1680. EXPORT_SYMBOL(acpi_resources_are_enforced);
  1681. bool acpi_osi_is_win8(void)
  1682. {
  1683. return acpi_gbl_osi_data >= ACPI_OSI_WIN_8;
  1684. }
  1685. EXPORT_SYMBOL(acpi_osi_is_win8);
  1686. /*
  1687. * Deallocate the memory for a spinlock.
  1688. */
  1689. void acpi_os_delete_lock(acpi_spinlock handle)
  1690. {
  1691. ACPI_FREE(handle);
  1692. }
  1693. /*
  1694. * Acquire a spinlock.
  1695. *
  1696. * handle is a pointer to the spinlock_t.
  1697. */
  1698. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1699. {
  1700. acpi_cpu_flags flags;
  1701. spin_lock_irqsave(lockp, flags);
  1702. return flags;
  1703. }
  1704. /*
  1705. * Release a spinlock. See above.
  1706. */
  1707. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1708. {
  1709. spin_unlock_irqrestore(lockp, flags);
  1710. }
  1711. #ifndef ACPI_USE_LOCAL_CACHE
  1712. /*******************************************************************************
  1713. *
  1714. * FUNCTION: acpi_os_create_cache
  1715. *
  1716. * PARAMETERS: name - Ascii name for the cache
  1717. * size - Size of each cached object
  1718. * depth - Maximum depth of the cache (in objects) <ignored>
  1719. * cache - Where the new cache object is returned
  1720. *
  1721. * RETURN: status
  1722. *
  1723. * DESCRIPTION: Create a cache object
  1724. *
  1725. ******************************************************************************/
  1726. acpi_status
  1727. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1728. {
  1729. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1730. if (*cache == NULL)
  1731. return AE_ERROR;
  1732. else
  1733. return AE_OK;
  1734. }
  1735. /*******************************************************************************
  1736. *
  1737. * FUNCTION: acpi_os_purge_cache
  1738. *
  1739. * PARAMETERS: Cache - Handle to cache object
  1740. *
  1741. * RETURN: Status
  1742. *
  1743. * DESCRIPTION: Free all objects within the requested cache.
  1744. *
  1745. ******************************************************************************/
  1746. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1747. {
  1748. kmem_cache_shrink(cache);
  1749. return (AE_OK);
  1750. }
  1751. /*******************************************************************************
  1752. *
  1753. * FUNCTION: acpi_os_delete_cache
  1754. *
  1755. * PARAMETERS: Cache - Handle to cache object
  1756. *
  1757. * RETURN: Status
  1758. *
  1759. * DESCRIPTION: Free all objects within the requested cache and delete the
  1760. * cache object.
  1761. *
  1762. ******************************************************************************/
  1763. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1764. {
  1765. kmem_cache_destroy(cache);
  1766. return (AE_OK);
  1767. }
  1768. /*******************************************************************************
  1769. *
  1770. * FUNCTION: acpi_os_release_object
  1771. *
  1772. * PARAMETERS: Cache - Handle to cache object
  1773. * Object - The object to be released
  1774. *
  1775. * RETURN: None
  1776. *
  1777. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1778. * the object is deleted.
  1779. *
  1780. ******************************************************************************/
  1781. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1782. {
  1783. kmem_cache_free(cache, object);
  1784. return (AE_OK);
  1785. }
  1786. #endif
  1787. static int __init acpi_no_static_ssdt_setup(char *s)
  1788. {
  1789. acpi_gbl_disable_ssdt_table_install = TRUE;
  1790. pr_info("ACPI: static SSDT installation disabled\n");
  1791. return 0;
  1792. }
  1793. early_param("acpi_no_static_ssdt", acpi_no_static_ssdt_setup);
  1794. static int __init acpi_disable_return_repair(char *s)
  1795. {
  1796. printk(KERN_NOTICE PREFIX
  1797. "ACPI: Predefined validation mechanism disabled\n");
  1798. acpi_gbl_disable_auto_repair = TRUE;
  1799. return 1;
  1800. }
  1801. __setup("acpica_no_return_repair", acpi_disable_return_repair);
  1802. acpi_status __init acpi_os_initialize(void)
  1803. {
  1804. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1805. acpi_os_map_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1806. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1807. acpi_os_map_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1808. if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) {
  1809. /*
  1810. * Use acpi_os_map_generic_address to pre-map the reset
  1811. * register if it's in system memory.
  1812. */
  1813. int rv;
  1814. rv = acpi_os_map_generic_address(&acpi_gbl_FADT.reset_register);
  1815. pr_debug(PREFIX "%s: map reset_reg status %d\n", __func__, rv);
  1816. }
  1817. acpi_os_initialized = true;
  1818. return AE_OK;
  1819. }
  1820. acpi_status __init acpi_os_initialize1(void)
  1821. {
  1822. kacpid_wq = alloc_workqueue("kacpid", 0, 1);
  1823. kacpi_notify_wq = alloc_workqueue("kacpi_notify", 0, 1);
  1824. kacpi_hotplug_wq = alloc_ordered_workqueue("kacpi_hotplug", 0);
  1825. BUG_ON(!kacpid_wq);
  1826. BUG_ON(!kacpi_notify_wq);
  1827. BUG_ON(!kacpi_hotplug_wq);
  1828. acpi_install_interface_handler(acpi_osi_handler);
  1829. acpi_osi_setup_late();
  1830. return AE_OK;
  1831. }
  1832. acpi_status acpi_os_terminate(void)
  1833. {
  1834. if (acpi_irq_handler) {
  1835. acpi_os_remove_interrupt_handler(acpi_gbl_FADT.sci_interrupt,
  1836. acpi_irq_handler);
  1837. }
  1838. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe1_block);
  1839. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xgpe0_block);
  1840. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1b_event_block);
  1841. acpi_os_unmap_generic_address(&acpi_gbl_FADT.xpm1a_event_block);
  1842. if (acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER)
  1843. acpi_os_unmap_generic_address(&acpi_gbl_FADT.reset_register);
  1844. destroy_workqueue(kacpid_wq);
  1845. destroy_workqueue(kacpi_notify_wq);
  1846. destroy_workqueue(kacpi_hotplug_wq);
  1847. return AE_OK;
  1848. }
  1849. acpi_status acpi_os_prepare_sleep(u8 sleep_state, u32 pm1a_control,
  1850. u32 pm1b_control)
  1851. {
  1852. int rc = 0;
  1853. if (__acpi_os_prepare_sleep)
  1854. rc = __acpi_os_prepare_sleep(sleep_state,
  1855. pm1a_control, pm1b_control);
  1856. if (rc < 0)
  1857. return AE_ERROR;
  1858. else if (rc > 0)
  1859. return AE_CTRL_SKIP;
  1860. return AE_OK;
  1861. }
  1862. void acpi_os_set_prepare_sleep(int (*func)(u8 sleep_state,
  1863. u32 pm1a_ctrl, u32 pm1b_ctrl))
  1864. {
  1865. __acpi_os_prepare_sleep = func;
  1866. }
  1867. acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a,
  1868. u32 val_b)
  1869. {
  1870. int rc = 0;
  1871. if (__acpi_os_prepare_extended_sleep)
  1872. rc = __acpi_os_prepare_extended_sleep(sleep_state,
  1873. val_a, val_b);
  1874. if (rc < 0)
  1875. return AE_ERROR;
  1876. else if (rc > 0)
  1877. return AE_CTRL_SKIP;
  1878. return AE_OK;
  1879. }
  1880. void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
  1881. u32 val_a, u32 val_b))
  1882. {
  1883. __acpi_os_prepare_extended_sleep = func;
  1884. }