osl.c 36 KB

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