xref: /haiku/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
1 /*
2  * Copyright 2005-2006, 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,
50 	size_t numBytes, uint32 spec, uint32 protection, void **virtualAddress)
51 {
52 	fArea = map_physical_memory(name, physicalAddress, numBytes, spec,
53 		protection, virtualAddress);
54 	return fArea;
55 }
56 
57 
58 void
59 PhysicalMemoryMapper::Keep()
60 {
61 	fArea = -1;
62 }
63 
64 
65 //	#pragma mark -
66 
67 
68 status_t
69 vesa_init(vesa_info &info)
70 {
71 	frame_buffer_boot_info *bufferInfo
72 		= (frame_buffer_boot_info *)get_boot_item(FRAME_BUFFER_BOOT_INFO);
73 	if (bufferInfo == NULL)
74 		return B_ERROR;
75 
76 	info.shared_area = create_area("vesa shared info", (void **)&info.shared_info,
77 			B_ANY_KERNEL_ADDRESS, ROUND_TO_PAGE_SIZE(sizeof(vesa_shared_info)),
78 			B_FULL_LOCK,
79 			B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_USER_CLONEABLE_AREA);
80 	if (info.shared_area < B_OK)
81 		return info.shared_area;
82 
83 	memset((void *)info.shared_info, 0, sizeof(vesa_shared_info));
84 
85 	info.shared_info->frame_buffer_area = bufferInfo->area;
86 	info.shared_info->frame_buffer = (uint8 *)bufferInfo->frame_buffer;
87 
88 	info.shared_info->current_mode.virtual_width = bufferInfo->width;
89 	info.shared_info->current_mode.virtual_height = bufferInfo->height;
90 	switch (bufferInfo->depth) {
91 		case 4:
92 			// ???
93 			break;
94 		case 8:
95 			info.shared_info->current_mode.space = B_CMAP8;
96 			break;
97 		case 15:
98 			info.shared_info->current_mode.space = B_RGB15;
99 			break;
100 		case 16:
101 			info.shared_info->current_mode.space = B_RGB16;
102 			break;
103 		case 24:
104 			info.shared_info->current_mode.space = B_RGB24;
105 			break;
106 		case 32:
107 			info.shared_info->current_mode.space = B_RGB32;
108 			break;
109 	}
110 	info.shared_info->bytes_per_row = bufferInfo->bytes_per_row;
111 
112 	physical_entry mapping;
113 	get_memory_map((void *)info.shared_info->frame_buffer, B_PAGE_SIZE,
114 		&mapping, 1);
115 	info.shared_info->physical_frame_buffer = (uint8 *)mapping.address;
116 
117 	dprintf(DEVICE_NAME ": vesa_init() completed successfully!\n");
118 	return B_OK;
119 }
120 
121 
122 void
123 vesa_uninit(vesa_info &info)
124 {
125 	dprintf(DEVICE_NAME": vesa_uninit()\n");
126 
127 	delete_area(info.shared_info->frame_buffer_area);
128 	delete_area(info.shared_area);
129 }
130 
131