1 /* 2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <boot_item.h> 8 #include <frame_buffer_console.h> 9 10 #include "vesa_info.h" 11 #include "driver.h" 12 #include "utility.h" 13 14 #include "util/kernel_cpp.h" 15 16 #include <string.h> 17 18 19 class PhysicalMemoryMapper { 20 public: 21 PhysicalMemoryMapper(); 22 ~PhysicalMemoryMapper(); 23 24 area_id Map(const char *name, void *physicalAddress, size_t numBytes, 25 uint32 spec, uint32 protection, void **virtualAddress); 26 status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; } 27 void Keep(); 28 29 private: 30 area_id fArea; 31 }; 32 33 34 PhysicalMemoryMapper::PhysicalMemoryMapper() 35 : 36 fArea(-1) 37 { 38 } 39 40 41 PhysicalMemoryMapper::~PhysicalMemoryMapper() 42 { 43 if (fArea >= B_OK) 44 delete_area(fArea); 45 } 46 47 48 area_id 49 PhysicalMemoryMapper::Map(const char *name, void *physicalAddress, size_t numBytes, 50 uint32 spec, uint32 protection, void **virtualAddress) 51 { 52 fArea = map_physical_memory(name, physicalAddress, numBytes, spec, protection, virtualAddress); 53 return fArea; 54 } 55 56 57 void 58 PhysicalMemoryMapper::Keep() 59 { 60 fArea = -1; 61 } 62 63 64 // #pragma mark - 65 66 67 status_t 68 vesa_init(vesa_info &info) 69 { 70 frame_buffer_boot_info *bufferInfo 71 = (frame_buffer_boot_info *)get_boot_item(FRAME_BUFFER_BOOT_INFO); 72 if (bufferInfo == NULL) 73 return B_ERROR; 74 75 info.shared_area = create_area("vesa shared info", (void **)&info.shared_info, 76 B_ANY_KERNEL_ADDRESS, 77 ROUND_TO_PAGE_SIZE(sizeof(vesa_shared_info)), 78 B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_USER_CLONEABLE_AREA); 79 if (info.shared_area < B_OK) 80 return info.shared_area; 81 82 memset((void *)info.shared_info, 0, sizeof(vesa_shared_info)); 83 84 info.shared_info->frame_buffer_area = bufferInfo->area; 85 info.shared_info->frame_buffer = (uint8 *)bufferInfo->frame_buffer; 86 87 info.shared_info->current_mode.virtual_width = bufferInfo->width; 88 info.shared_info->current_mode.virtual_height = bufferInfo->height; 89 switch (bufferInfo->depth) { 90 case 4: 91 // ??? 92 break; 93 case 8: 94 info.shared_info->current_mode.space = B_CMAP8; 95 break; 96 case 15: 97 info.shared_info->current_mode.space = B_RGB15; 98 break; 99 case 16: 100 info.shared_info->current_mode.space = B_RGB16; 101 break; 102 case 24: 103 info.shared_info->current_mode.space = B_RGB24; 104 break; 105 case 32: 106 info.shared_info->current_mode.space = B_RGB32; 107 break; 108 } 109 info.shared_info->bytes_per_row = bufferInfo->bytes_per_row; 110 111 physical_entry mapping; 112 get_memory_map((void *)info.shared_info->frame_buffer, B_PAGE_SIZE, &mapping, 1); 113 info.shared_info->physical_frame_buffer = (uint8 *)mapping.address; 114 115 dprintf(DEVICE_NAME "vesa_init() completed successfully!\n"); 116 return B_OK; 117 } 118 119 120 void 121 vesa_uninit(vesa_info &info) 122 { 123 dprintf(DEVICE_NAME": vesa_uninit()\n"); 124 125 delete_area(info.shared_info->frame_buffer_area); 126 delete_area(info.shared_area); 127 } 128 129