osl.c 39 KB

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