~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/acpi/os.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  os.c - OS-dependent functions
  3  *
  4  *  Copyright (C) 2000 Andrew Henroid
  5  *
  6  *  This program is free software; you can redistribute it and/or modify
  7  *  it under the terms of the GNU General Public License as published by
  8  *  the Free Software Foundation; either version 2 of the License, or
  9  *  (at your option) any later version.
 10  *
 11  *  This program is distributed in the hope that it will be useful,
 12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  *  GNU General Public License for more details.
 15  *
 16  *  You should have received a copy of the GNU General Public License
 17  *  along with this program; if not, write to the Free Software
 18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19  */
 20 
 21 #include <linux/kernel.h>
 22 #include <linux/types.h>
 23 #include <linux/slab.h>
 24 #include <linux/mm.h>
 25 #include <linux/pci.h>
 26 #include <linux/acpi.h>
 27 #include <asm/io.h>
 28 #include <asm/delay.h>
 29 #include "acpi.h"
 30 #include "driver.h"
 31 
 32 #define _COMPONENT      OS_DEPENDENT
 33         MODULE_NAME     ("os")
 34 
 35 static int acpi_irq_irq = 0;
 36 static OSD_HANDLER acpi_irq_handler = NULL;
 37 static void *acpi_irq_context = NULL;
 38 
 39 #ifdef ENABLE_DEBUGGER
 40 
 41 #include <linux/kdb.h>
 42 
 43 /* stuff for debugger support */
 44 int acpi_in_debugger = 0;
 45 extern NATIVE_CHAR line_buf[80];
 46 
 47 #endif
 48 
 49 
 50 ACPI_STATUS
 51 acpi_os_initialize(void)
 52 {
 53         return AE_OK;
 54 }
 55 
 56 ACPI_STATUS
 57 acpi_os_terminate(void)
 58 {
 59         if (acpi_irq_handler) {
 60                 acpi_os_remove_interrupt_handler(acpi_irq_irq,
 61                                                  acpi_irq_handler);
 62         }
 63         return AE_OK;
 64 }
 65 
 66 s32
 67 acpi_os_printf(const NATIVE_CHAR *fmt,...)
 68 {
 69         s32 size;
 70         va_list args;
 71         va_start(args, fmt);
 72         size = acpi_os_vprintf(fmt, args);
 73         va_end(args);
 74         return size;
 75 }
 76 
 77 s32
 78 acpi_os_vprintf(const NATIVE_CHAR *fmt, va_list args)
 79 {
 80         static char buffer[512];
 81         int size = vsprintf(buffer, fmt, args);
 82 
 83 #ifdef ENABLE_DEBUGGER
 84         if (acpi_in_debugger) {
 85                 kdb_printf("%s", buffer);
 86         } else {
 87                 printk("%s", buffer);
 88         }
 89 #else
 90         printk("%s", buffer);
 91 #endif
 92 
 93         return size;
 94 }
 95 
 96 void *
 97 acpi_os_allocate(u32 size)
 98 {
 99         return kmalloc(size, GFP_KERNEL);
100 }
101 
102 void *
103 acpi_os_callocate(u32 size)
104 {
105         void *ptr = acpi_os_allocate(size);
106         if (ptr)
107                 memset(ptr, 0, size);
108         return ptr;
109 }
110 
111 void
112 acpi_os_free(void *ptr)
113 {
114         kfree(ptr);
115 }
116 
117 ACPI_STATUS
118 acpi_os_map_memory(ACPI_PHYSICAL_ADDRESS phys, u32 size, void **virt)
119 {
120         if (phys > ULONG_MAX) {
121                 printk(KERN_ERR "ACPI: Cannot map memory that high\n");
122                 return AE_ERROR;
123         }
124 
125         if ((unsigned long) phys < virt_to_phys(high_memory)) {
126                 *virt = phys_to_virt((unsigned long) phys);
127                 return AE_OK;
128         }
129 
130         *virt = ioremap((unsigned long) phys, size);
131         if (!*virt)
132                 return AE_ERROR;
133 
134         return AE_OK;
135 }
136 
137 void
138 acpi_os_unmap_memory(void *virt, u32 size)
139 {
140         if (virt >= high_memory)
141                 iounmap(virt);
142 }
143 
144 static void
145 acpi_irq(int irq, void *dev_id, struct pt_regs *regs)
146 {
147         (*acpi_irq_handler)(acpi_irq_context);
148 }
149 
150 ACPI_STATUS
151 acpi_os_install_interrupt_handler(u32 irq, OSD_HANDLER handler, void *context)
152 {
153         acpi_irq_irq = irq;
154         acpi_irq_handler = handler;
155         acpi_irq_context = context;
156         if (request_irq(irq,
157                         acpi_irq,
158                         SA_SHIRQ,
159                         "acpi",
160                         acpi_irq)) {
161                 printk(KERN_ERR "ACPI: SCI (IRQ%d) allocation failed\n", irq);
162                 return AE_ERROR;
163         }
164         return AE_OK;
165 }
166 
167 ACPI_STATUS
168 acpi_os_remove_interrupt_handler(u32 irq, OSD_HANDLER handler)
169 {
170         if (acpi_irq_handler) {
171                 free_irq(irq, acpi_irq);
172                 acpi_irq_handler = NULL;
173         }
174         return AE_OK;
175 }
176 
177 /*
178  * Running in interpreter thread context, safe to sleep
179  */
180 
181 void
182 acpi_os_sleep(u32 sec, u32 ms)
183 {
184         current->state = TASK_INTERRUPTIBLE;
185         schedule_timeout(HZ * sec + (ms * HZ) / 1000);
186 }
187 
188 void
189 acpi_os_sleep_usec(u32 us)
190 {
191         udelay(us);
192 }
193 
194 u8
195 acpi_os_in8(ACPI_IO_ADDRESS port)
196 {
197         return inb(port);
198 }
199 
200 u16
201 acpi_os_in16(ACPI_IO_ADDRESS port)
202 {
203         return inw(port);
204 }
205 
206 u32
207 acpi_os_in32(ACPI_IO_ADDRESS port)
208 {
209         return inl(port);
210 }
211 
212 void
213 acpi_os_out8(ACPI_IO_ADDRESS port, u8 val)
214 {
215         outb(val, port);
216 }
217 
218 void
219 acpi_os_out16(ACPI_IO_ADDRESS port, u16 val)
220 {
221         outw(val, port);
222 }
223 
224 void
225 acpi_os_out32(ACPI_IO_ADDRESS port, u32 val)
226 {
227         outl(val, port);
228 }
229 
230 UINT8
231 acpi_os_mem_in8 (ACPI_PHYSICAL_ADDRESS phys_addr)
232 {
233         return (*(u8*) (u32) phys_addr);
234 }
235 
236 UINT16
237 acpi_os_mem_in16 (ACPI_PHYSICAL_ADDRESS phys_addr)
238 {
239         return (*(u16*) (u32) phys_addr);
240 }
241 
242 UINT32
243 acpi_os_mem_in32 (ACPI_PHYSICAL_ADDRESS phys_addr)
244 {
245         return (*(u32*) (u32) phys_addr);
246 }
247 
248 void
249 acpi_os_mem_out8 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT8 value)
250 {
251         *(u8*) (u32) phys_addr = value;
252 }
253 
254 void
255 acpi_os_mem_out16 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT16 value)
256 {
257         *(u16*) (u32) phys_addr = value;
258 }
259 
260 void
261 acpi_os_mem_out32 (ACPI_PHYSICAL_ADDRESS phys_addr, UINT32 value)
262 {
263         *(u32*) (u32) phys_addr = value;
264 }
265 
266 ACPI_STATUS
267 acpi_os_read_pci_cfg_byte(
268                           u32 bus,
269                           u32 func,
270                           u32 addr,
271                           u8 * val)
272 {
273         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
274         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
275         if (!val || !dev || pci_read_config_byte(dev, addr, val))
276                 return AE_ERROR;
277         return AE_OK;
278 }
279 
280 ACPI_STATUS
281 acpi_os_read_pci_cfg_word(
282                           u32 bus,
283                           u32 func,
284                           u32 addr,
285                           u16 * val)
286 {
287         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
288         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
289         if (!val || !dev || pci_read_config_word(dev, addr, val))
290                 return AE_ERROR;
291         return AE_OK;
292 }
293 
294 ACPI_STATUS
295 acpi_os_read_pci_cfg_dword(
296                            u32 bus,
297                            u32 func,
298                            u32 addr,
299                            u32 * val)
300 {
301         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
302         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
303         if (!val || !dev || pci_read_config_dword(dev, addr, val))
304                 return AE_ERROR;
305         return AE_OK;
306 }
307 
308 ACPI_STATUS
309 acpi_os_write_pci_cfg_byte(
310                            u32 bus,
311                            u32 func,
312                            u32 addr,
313                            u8 val)
314 {
315         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
316         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
317         if (!dev || pci_write_config_byte(dev, addr, val))
318                 return AE_ERROR;
319         return AE_OK;
320 }
321 
322 ACPI_STATUS
323 acpi_os_write_pci_cfg_word(
324                            u32 bus,
325                            u32 func,
326                            u32 addr,
327                            u16 val)
328 {
329         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
330         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
331         if (!dev || pci_write_config_word(dev, addr, val))
332                 return AE_ERROR;
333         return AE_OK;
334 }
335 
336 ACPI_STATUS
337 acpi_os_write_pci_cfg_dword(
338                             u32 bus,
339                             u32 func,
340                             u32 addr,
341                             u32 val)
342 {
343         int devfn = PCI_DEVFN((func >> 16) & 0xffff, func & 0xffff);
344         struct pci_dev *dev = pci_find_slot(bus & 0xffff, devfn);
345         if (!dev || pci_write_config_dword(dev, addr, val))
346                 return AE_ERROR;
347         return AE_OK;
348 }
349 
350 /*
351  * Queue for interpreter thread
352  */
353 
354 ACPI_STATUS
355 acpi_os_queue_for_execution(
356                             u32 priority,
357                             OSD_EXECUTION_CALLBACK callback,
358                             void *context)
359 {
360         if (acpi_run(callback, context))
361                 return AE_ERROR;
362         return AE_OK;
363 }
364 
365 /*
366  * Semaphores are unused, interpreter access is single threaded
367  */
368 
369 ACPI_STATUS
370 acpi_os_create_semaphore(u32 max_units, u32 init, ACPI_HANDLE * handle)
371 {
372         /* a hack to fake out sems until we implement them */
373         *handle = (ACPI_HANDLE) handle;
374         return AE_OK;
375 }
376 
377 ACPI_STATUS
378 acpi_os_delete_semaphore(ACPI_HANDLE handle)
379 {
380         return AE_OK;
381 }
382 
383 ACPI_STATUS
384 acpi_os_wait_semaphore(ACPI_HANDLE handle, u32 units, u32 timeout)
385 {
386         return AE_OK;
387 }
388 
389 ACPI_STATUS
390 acpi_os_signal_semaphore(ACPI_HANDLE handle, u32 units)
391 {
392         return AE_OK;
393 }
394 
395 ACPI_STATUS
396 acpi_os_breakpoint(NATIVE_CHAR *msg)
397 {
398         acpi_os_printf("breakpoint: %s", msg);
399         return AE_OK;
400 }
401 
402 void
403 acpi_os_dbg_trap(char *msg)
404 {
405         acpi_os_printf("trap: %s", msg);
406 }
407 
408 void
409 acpi_os_dbg_assert(void *failure, void *file, u32 line, NATIVE_CHAR *msg)
410 {
411         acpi_os_printf("assert: %s", msg);
412 }
413 
414 u32
415 acpi_os_get_line(NATIVE_CHAR *buffer)
416 {
417 
418 #ifdef ENABLE_DEBUGGER
419         if (acpi_in_debugger) {
420                 u32 chars;
421 
422                 kdb_read(buffer, sizeof(line_buf));
423 
424                 /* remove the CR kdb includes */
425                 chars = strlen(buffer) - 1;
426                 buffer[chars] = '\0';
427         }
428 #endif
429 
430         return 0;
431 }
432 
433 /*
434  * We just have to assume we're dealing with valid memory
435  */
436 
437 BOOLEAN
438 acpi_os_readable(void *ptr, u32 len)
439 {
440         return 1;
441 }
442 
443 BOOLEAN
444 acpi_os_writable(void *ptr, u32 len)
445 {
446         return 1;
447 }
448 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.