osl.c 37 KB

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