osl.c 37 KB

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