osl.c 37 KB

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