osl.c 36 KB

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