1/* 2 * ice1712 BeOS/Haiku Driver for VIA - VT1712 Multi Channel Audio Controller 3 * 4 * Copyright (c) 2002, Jerome Duval (jerome.duval@free.fr) 5 * Copyright (c) 2003, Marcus Overhagen (marcus@overhagen.de) 6 * Copyright (c) 2007, Jerome Leveque (leveque.jerome@neuf.fr) 7 * 8 * All rights reserved 9 * Distributed under the terms of the MIT license. 10 */ 11 12#include <Errors.h> 13#include <OS.h> 14#include <string.h> 15 16#include "debug.h" 17#include "util.h" 18 19spinlock slock = 0; 20 21uint32 round_to_pagesize(uint32 size); 22 23 24cpu_status 25lock(void) 26{ 27 cpu_status status = disable_interrupts(); 28 acquire_spinlock(&slock); 29 return status; 30} 31 32 33void 34unlock(cpu_status status) 35{ 36 release_spinlock(&slock); 37 restore_interrupts(status); 38} 39 40 41uint32 42round_to_pagesize(uint32 size) 43{ 44 return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); 45} 46 47 48area_id 49alloc_mem(void **phy, void **log, size_t size, const char *name) 50{ 51// TODO: phy should be phys_addr_t*! 52 physical_entry pe; 53 void * logadr; 54 area_id areaid; 55 status_t rv; 56 57 TRACE("allocating %#08X bytes for %s\n", (int)size, name); 58 59 size = round_to_pagesize(size); 60 areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size, 61 B_32_BIT_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); 62 // TODO: The rest of the code doesn't deal correctly with physical 63 // addresses > 4 GB, so we have to force 32 bit addresses here. 64 if (areaid < B_OK) { 65 TRACE("couldn't allocate area %s\n",name); 66 return B_ERROR; 67 } 68 rv = get_memory_map(logadr,size,&pe,1); 69 if (rv < B_OK) { 70 delete_area(areaid); 71 TRACE("couldn't map %s\n",name); 72 return B_ERROR; 73 } 74 memset(logadr,0,size); 75 if (log) 76 *log = logadr; 77 if (phy) 78 *phy = (void*)(addr_t)pe.address; 79 TRACE("area = %d, size = %#08X, log = %#08X, phy = %#08X\n", 80 (int)areaid, (int)size, (int)logadr, (int)pe.address); 81 return areaid; 82} 83 84