osl.c 37 KB

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