BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / accelerants / radeon / driver_wrapper.c
blob6c793f68deb85a3670eda9b5b35540b5abf7cc1e
1 /*
2 Copyright (c) 2003, Thomas Kurschel
5 Part of Radeon accelerant
7 Kernel driver wrapper
8 */
10 #include "radeon_accelerant.h"
11 #include <sys/ioctl.h>
12 #include "rbbm_regs.h"
13 #include "mmio.h"
16 status_t Radeon_WaitForIdle( accelerator_info *ai, bool keep_lock )
18 radeon_wait_for_idle wfi;
20 wfi.magic = RADEON_PRIVATE_DATA_MAGIC;
21 wfi.keep_lock = keep_lock;
23 return ioctl( ai->fd, RADEON_WAITFORIDLE, &wfi, sizeof( wfi ));
26 // wait until "entries" FIFO entries are empty
27 // lock must be hold
28 status_t Radeon_WaitForFifo( accelerator_info *ai, int entries )
30 while( 1 ) {
31 bigtime_t start_time = system_time();
33 do {
34 int slots = INREG( ai->regs, RADEON_RBBM_STATUS ) & RADEON_RBBM_FIFOCNT_MASK;
36 if ( slots >= entries )
37 return B_OK;
39 snooze( 1 );
40 } while( system_time() - start_time < 1000000 );
42 Radeon_ResetEngine( ai );
45 return B_ERROR;
48 void Radeon_ResetEngine( accelerator_info *ai )
50 radeon_no_arg na;
52 na.magic = RADEON_PRIVATE_DATA_MAGIC;
54 ioctl( ai->fd, RADEON_RESETENGINE, &na, sizeof( na ));
58 status_t Radeon_VIPRead( accelerator_info *ai, uint channel, uint address, uint32 *data )
60 radeon_vip_read vr;
61 status_t res;
63 vr.magic = RADEON_PRIVATE_DATA_MAGIC;
64 vr.channel = channel;
65 vr.address = address;
66 vr.lock = false;
68 res = ioctl( ai->fd, RADEON_VIPREAD, &vr, sizeof( vr ));
70 if( res == B_OK )
71 *data = vr.data;
73 return res;
77 status_t Radeon_VIPWrite( accelerator_info *ai, uint8 channel, uint address, uint32 data )
79 radeon_vip_write vw;
81 vw.magic = RADEON_PRIVATE_DATA_MAGIC;
82 vw.channel = channel;
83 vw.address = address;
84 vw.data = data;
85 vw.lock = false;
87 return ioctl( ai->fd, RADEON_VIPWRITE, &vw, sizeof( vw ));
90 int Radeon_FindVIPDevice( accelerator_info *ai, uint32 device_id )
92 radeon_find_vip_device fvd;
93 status_t res;
95 fvd.magic = RADEON_PRIVATE_DATA_MAGIC;
96 fvd.device_id = device_id;
98 res = ioctl( ai->fd, RADEON_FINDVIPDEVICE, &fvd, sizeof( fvd ));
100 if( res == B_OK )
101 return fvd.channel;
102 else
103 return -1;