1 /* 2 * Copyright 2004-2015 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Jérôme Duval, jerome.duval@free.fr 7 * Marcus Overhagen, marcus@overhagen.de 8 * Jérôme Lévêque, leveque.jerome@gmail.com 9 */ 10 11 #include <Errors.h> 12 #include <OS.h> 13 #include <string.h> 14 15 #include <vm/vm.h> 16 #include <vm/VMAddressSpace.h> 17 18 #include "debug.h" 19 #include "util.h" 20 21 static spinlock slock = B_SPINLOCK_INITIALIZER; 22 23 cpu_status 24 lock(void) 25 { 26 cpu_status status = disable_interrupts(); 27 acquire_spinlock(&slock); 28 return status; 29 } 30 31 32 void 33 unlock(cpu_status status) 34 { 35 release_spinlock(&slock); 36 restore_interrupts(status); 37 } 38 39 40 area_id 41 alloc_mem(physical_entry *phy, addr_t *log, size_t size, const char *name) 42 { 43 void * logadr; 44 area_id areaid; 45 status_t rv; 46 virtual_address_restrictions virtualRestrictions = {}; 47 virtualRestrictions.address_specification = B_ANY_KERNEL_ADDRESS; 48 physical_address_restrictions physicalRestrictions = {}; 49 physicalRestrictions.high_address = 1 << 28; 50 // ICE1712 chipset can not deal with memory area beyond 256MB 51 52 ITRACE("Allocating %s: ", name); 53 54 areaid = vm_create_anonymous_area(B_SYSTEM_TEAM, name, size, B_CONTIGUOUS, 55 B_READ_AREA | B_WRITE_AREA, 0, 0, 56 &virtualRestrictions, &physicalRestrictions, true, &logadr); 57 58 if (areaid < B_OK) { 59 ITRACE("couldn't allocate\n"); 60 return B_ERROR; 61 } 62 rv = get_memory_map(logadr, size, phy, 1); 63 if (rv < B_OK) { 64 delete_area(areaid); 65 ITRACE("couldn't map\n"); 66 return B_ERROR; 67 } 68 69 if (log) 70 *log = (addr_t)logadr; 71 72 ITRACE("area = %" B_PRId32 ", size = %" B_PRIuSIZE ", log = 0x%" \ 73 B_PRIXADDR ", phy = 0x%" B_PRIXPHYSADDR "\n", areaid, size, 74 *log, phy->address); 75 76 return areaid; 77 } 78 79