xref: /haiku/src/add-ons/kernel/drivers/graphics/radeon_hd/radeon_hd.cpp (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2  * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Axel Dörfler, axeld@pinc-software.de
7  *		Clemens Zeidler, haiku@clemens-zeidler.de
8  */
9 
10 
11 #include "radeon_hd.h"
12 
13 #include "AreaKeeper.h"
14 #include "driver.h"
15 #include "utility.h"
16 
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <string.h>
20 #include <errno.h>
21 
22 #include <driver_settings.h>
23 #include <util/kernel_cpp.h>
24 #include <vm/vm.h>
25 
26 
27 #define TRACE_DEVICE
28 #ifdef TRACE_DEVICE
29 #	define TRACE(x) dprintf x
30 #else
31 #	define TRACE(x) ;
32 #endif
33 
34 
35 //	#pragma mark -
36 
37 
38 #define RHD_FB_BAR   0
39 #define RHD_MMIO_BAR 2
40 
41 
42 status_t
43 radeon_hd_init(radeon_info &info)
44 {
45 	// memory mapped I/O
46 
47 	AreaKeeper sharedCreator;
48 	info.shared_area = sharedCreator.Create("radeon hd shared info",
49 		(void **)&info.shared_info, B_ANY_KERNEL_ADDRESS,
50 		ROUND_TO_PAGE_SIZE(sizeof(radeon_shared_info)), B_FULL_LOCK, 0);
51 	if (info.shared_area < B_OK) {
52 		return info.shared_area;
53 	}
54 
55 	memset((void *)info.shared_info, 0, sizeof(radeon_shared_info));
56 
57 	AreaKeeper mmioMapper;
58 	info.registers_area = mmioMapper.Map("radeon hd mmio",
59 		(void *)info.pci->u.h0.base_registers[RHD_MMIO_BAR],
60 		info.pci->u.h0.base_register_sizes[RHD_MMIO_BAR],
61 		B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
62 		(void **)&info.registers);
63 	if (mmioMapper.InitCheck() < B_OK) {
64 		dprintf(DEVICE_NAME ": could not map memory I/O!\n");
65 		return info.registers_area;
66 	}
67 
68 	AreaKeeper frambufferMapper;
69 	info.framebuffer_area = frambufferMapper.Map("radeon hd framebuffer",
70 		(void *)info.pci->u.h0.base_registers[RHD_FB_BAR],
71 		info.pci->u.h0.base_register_sizes[RHD_FB_BAR],
72 		B_ANY_KERNEL_ADDRESS, B_READ_AREA | B_WRITE_AREA,
73 		(void **)&info.shared_info->graphics_memory);
74 	if (frambufferMapper.InitCheck() < B_OK) {
75 		dprintf(DEVICE_NAME ": could not map framebuffer!\n");
76 		return info.framebuffer_area;
77 	}
78 
79 	// Turn on write combining for the area
80 	vm_set_area_memory_type(info.framebuffer_area,
81 		info.pci->u.h0.base_registers[RHD_FB_BAR], B_MTR_WC);
82 
83 	sharedCreator.Detach();
84 	mmioMapper.Detach();
85 	frambufferMapper.Detach();
86 
87 	info.shared_info->registers_area = info.registers_area;
88 	info.shared_info->frame_buffer_offset = 0;
89 	info.shared_info->physical_graphics_memory = info.pci->u.h0.base_registers[RHD_FB_BAR];
90 
91 	TRACE((DEVICE_NAME "radeon_hd_init() completed successfully!\n"));
92 	return B_OK;
93 }
94 
95 
96 void
97 radeon_hd_uninit(radeon_info &info)
98 {
99 	TRACE((DEVICE_NAME ": radeon_extreme_uninit()\n"));
100 
101 	delete_area(info.shared_area);
102 	delete_area(info.registers_area);
103 	delete_area(info.framebuffer_area);
104 }
105 
106