osl.c 33 KB

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