xref: /haiku/src/add-ons/accelerants/radeon/driver_wrapper.c (revision 8195a5a835117ab2da405e0d477153570b75d921)
1 /*
2 	Copyright (c) 2003, Thomas Kurschel
3 
4 
5 	Part of Radeon accelerant
6 
7 	Kernel driver wrapper
8 */
9 
10 #include "radeon_accelerant.h"
11 #include <sys/ioctl.h>
12 #include "rbbm_regs.h"
13 #include "mmio.h"
14 
15 
16 status_t Radeon_WaitForIdle( accelerator_info *ai, bool keep_lock )
17 {
18 	radeon_wait_for_idle wfi;
19 
20 	wfi.magic = RADEON_PRIVATE_DATA_MAGIC;
21 	wfi.keep_lock = keep_lock;
22 
23 	return ioctl( ai->fd, RADEON_WAITFORIDLE, &wfi, sizeof( wfi ));
24 }
25 
26 // wait until "entries" FIFO entries are empty
27 // lock must be hold
28 status_t Radeon_WaitForFifo( accelerator_info *ai, int entries )
29 {
30 	while( 1 ) {
31 		bigtime_t start_time = system_time();
32 
33 		do {
34 			int slots = INREG( ai->regs, RADEON_RBBM_STATUS ) & RADEON_RBBM_FIFOCNT_MASK;
35 
36 			if ( slots >= entries )
37 				return B_OK;
38 
39 			snooze( 1 );
40 		} while( system_time() - start_time < 1000000 );
41 
42 		Radeon_ResetEngine( ai );
43 	}
44 
45 	return B_ERROR;
46 }
47 
48 void Radeon_ResetEngine( accelerator_info *ai )
49 {
50 	radeon_no_arg na;
51 
52 	na.magic = RADEON_PRIVATE_DATA_MAGIC;
53 
54 	ioctl( ai->fd, RADEON_RESETENGINE, &na, sizeof( na ));
55 }
56 
57 
58 status_t Radeon_VIPRead( accelerator_info *ai, uint channel, uint address, uint32 *data )
59 {
60 	radeon_vip_read vr;
61 	status_t res;
62 
63 	vr.magic = RADEON_PRIVATE_DATA_MAGIC;
64 	vr.channel = channel;
65 	vr.address = address;
66 	vr.lock = false;
67 
68 	res = ioctl( ai->fd, RADEON_VIPREAD, &vr, sizeof( vr ));
69 
70 	if( res == B_OK )
71 		*data = vr.data;
72 
73 	return res;
74 }
75 
76 
77 status_t Radeon_VIPWrite( accelerator_info *ai, uint8 channel, uint address, uint32 data )
78 {
79 	radeon_vip_write vw;
80 
81 	vw.magic = RADEON_PRIVATE_DATA_MAGIC;
82 	vw.channel = channel;
83 	vw.address = address;
84 	vw.data = data;
85 	vw.lock = false;
86 
87 	return ioctl( ai->fd, RADEON_VIPWRITE, &vw, sizeof( vw ));
88 }
89 
90 int Radeon_FindVIPDevice( accelerator_info *ai, uint32 device_id )
91 {
92 	radeon_find_vip_device fvd;
93 	status_t res;
94 
95 	fvd.magic = RADEON_PRIVATE_DATA_MAGIC;
96 	fvd.device_id = device_id;
97 
98 	res = ioctl( ai->fd, RADEON_FINDVIPDEVICE, &fvd, sizeof( fvd ));
99 
100 	if( res == B_OK )
101 		return fvd.channel;
102 	else
103 		return -1;
104 }
105