Subversion Repositories Kolibri OS

Rev

Rev 5097 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5078 serge 1
#include 
2
#include 
3
#include 
4
#include "radeon_reg.h"
5
#include "radeon.h"
6
#include "bitmap.h"
7
 
8
#define KMS_DEV_CLOSE 0
9
#define KMS_DEV_INIT  1
10
#define KMS_DEV_READY 2
11
 
12
struct pci_device {
13
    uint16_t    domain;
14
    uint8_t     bus;
15
    uint8_t     dev;
16
    uint8_t     func;
17
    uint16_t    vendor_id;
18
    uint16_t    device_id;
19
    uint16_t    subvendor_id;
20
    uint16_t    subdevice_id;
21
    uint32_t    device_class;
22
    uint8_t     revision;
23
};
24
 
25
struct drm_device *main_device;
26
struct drm_file   *drm_file_handlers[256];
27
 
28
videomode_t usermode;
29
 
30
void cpu_detect();
31
 
32
int _stdcall display_handler(ioctl_t *io);
33
static char  log[256];
34
 
35
unsigned long volatile jiffies;
36
u64 jiffies_64;
37
 
38
struct workqueue_struct *system_wq;
39
int driver_wq_state;
40
 
41
int x86_clflush_size;
42
 
43
void ati_driver_thread()
44
{
45
    struct radeon_device *rdev = NULL;
46
    struct workqueue_struct *cwq = NULL;
47
//    static int dpms = 1;
48
//   static int dpms_lock = 0;
49
//    oskey_t   key;
50
    unsigned long irqflags;
51
    int tmp;
52
 
53
    printf("%s\n",__FUNCTION__);
54
 
55
    while(driver_wq_state == KMS_DEV_INIT)
56
    {
57
        jiffies = GetTimerTicks();
58
        jiffies_64 = jiffies;
59
        delay(1);
60
    };
61
 
62
    rdev = main_device->dev_private;
63
//    cwq = rdev->wq;
64
 
65
    asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(1),"c"(1));
66
    asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0x46),"d"(0x330));
67
    asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0xC6),"d"(0x330));
68
 
69
    while(driver_wq_state != KMS_DEV_CLOSE)
70
    {
71
        jiffies = GetTimerTicks();
72
#if 0
73
        key = get_key();
74
 
75
        if( (key.val != 1) && (key.state == 0x02))
76
        {
77
            if(key.code == 0x46 && dpms_lock == 0)
78
            {
79
                dpms_lock = 1;
80
                if(dpms == 1)
81
                {
82
                    i915_dpms(main_device, DRM_MODE_DPMS_OFF);
83
                    printf("dpms off\n");
84
                }
85
                else
86
                {
87
                    i915_dpms(main_device, DRM_MODE_DPMS_ON);
88
                    printf("dpms on\n");
89
                };
90
                dpms ^= 1;
91
                }
92
            else if(key.code == 0xC6)
93
                dpms_lock = 0;
94
        };
95
        spin_lock_irqsave(&cwq->lock, irqflags);
96
 
97
        while (!list_empty(&cwq->worklist))
98
        {
99
            struct work_struct *work = list_entry(cwq->worklist.next,
100
                                        struct work_struct, entry);
101
            work_func_t f = work->func;
102
            list_del_init(cwq->worklist.next);
103
 
104
            spin_unlock_irqrestore(&cwq->lock, irqflags);
105
            f(work);
106
            spin_lock_irqsave(&cwq->lock, irqflags);
107
        }
108
 
109
        spin_unlock_irqrestore(&cwq->lock, irqflags);
110
#endif
111
 
112
        delay(1);
113
    };
114
 
115
    asm volatile ("int $0x40"::"a"(-1));
116
}
117
 
118
u32_t  __attribute__((externally_visible)) drvEntry(int action, char *cmdline)
119
{
120
    struct radeon_device *rdev = NULL;
121
 
122
    const struct pci_device_id  *ent;
123
 
124
    int err = 0;
125
 
126
    if(action != 1)
127
    {
128
        driver_wq_state = KMS_DEV_CLOSE;
129
        return 0;
130
    };
131
 
132
    if( GetService("DISPLAY") != 0 )
133
        return 0;
134
 
135
    printf("Radeon v3.17-rc3 cmdline %s\n", cmdline);
136
 
137
    if( cmdline && *cmdline )
138
        parse_cmdline(cmdline, &usermode, log, &radeon_modeset);
139
 
140
    if( *log && !dbg_open(log))
141
    {
142
        printf("Can't open %s\nExit\n", log);
143
        return 0;
144
    }
145
 
146
    cpu_detect();
147
 
148
    err = enum_pci_devices();
149
    if( unlikely(err != 0) )
150
    {
151
        dbgprintf("Device enumeration failed\n");
152
        return 0;
153
    }
154
 
155
    driver_wq_state = KMS_DEV_INIT;
156
    CreateKernelThread(ati_driver_thread);
157
 
158
    err = ati_init();
159
    if(unlikely(err!= 0))
160
    {
161
        driver_wq_state = KMS_DEV_CLOSE;
162
        dbgprintf("Epic Fail :(\n");
163
        return 0;
164
    };
165
 
166
    driver_wq_state = KMS_DEV_READY;
167
 
168
    rdev = main_device->dev_private;
169
    printf("current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev));
170
    printf("current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev));
171
 
172
    err = RegService("DISPLAY", display_handler);
173
 
174
    if( err != 0)
175
        dbgprintf("DISPLAY service installed\n");
176
 
177
 
178
    return err;
179
};
180
 
181
 
182
 
183
#define CURRENT_API     0x0200      /*      2.00     */
184
#define COMPATIBLE_API  0x0100      /*      1.00     */
185
 
186
#define API_VERSION     (COMPATIBLE_API << 16) | CURRENT_API
187
 
188
#define SRV_GETVERSION          0
189
#define SRV_ENUM_MODES          1
190
#define SRV_SET_MODE            2
191
#define SRV_GET_CAPS            3
192
 
193
#define SRV_CREATE_SURFACE      10
194
#define SRV_DESTROY_SURFACE     11
195
#define SRV_LOCK_SURFACE        12
196
#define SRV_UNLOCK_SURFACE      13
197
#define SRV_RESIZE_SURFACE      14
198
#define SRV_BLIT_BITMAP         15
199
#define SRV_BLIT_TEXTURE        16
200
#define SRV_BLIT_VIDEO          17
201
 
202
 
203
 
204
int r600_video_blit(uint64_t src_offset, int  x, int y,
205
                    int w, int h, int pitch);
206
 
207
#define check_input(size) \
208
    if( unlikely((inp==NULL)||(io->inp_size != (size))) )   \
209
        break;
210
 
211
#define check_output(size) \
212
    if( unlikely((outp==NULL)||(io->out_size != (size))) )   \
213
        break;
214
 
215
int _stdcall display_handler(ioctl_t *io)
216
{
217
    int    retval = -1;
218
    u32_t *inp;
219
    u32_t *outp;
220
 
221
    inp = io->input;
222
    outp = io->output;
223
 
224
    switch(io->io_code)
225
    {
226
        case SRV_GETVERSION:
227
            check_output(4);
228
            *outp  = API_VERSION;
229
            retval = 0;
230
            break;
231
 
232
        case SRV_ENUM_MODES:
233
//            dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n",
234
//                       inp, io->inp_size, io->out_size );
235
            check_output(4);
236
            if( radeon_modeset)
237
                retval = get_videomodes((videomode_t*)inp, outp);
238
            break;
239
 
240
        case SRV_SET_MODE:
241
//            dbgprintf("SRV_SET_MODE inp %x inp_size %x\n",
242
//                       inp, io->inp_size);
243
            check_input(sizeof(videomode_t));
244
            if( radeon_modeset )
245
                retval = set_user_mode((videomode_t*)inp);
246
            break;
247
/*
248
        case SRV_GET_CAPS:
249
            retval = get_driver_caps((hwcaps_t*)inp);
250
            break;
251
 
252
        case SRV_CREATE_SURFACE:
253
//            check_input(8);
254
            retval = create_surface(main_drm_device, (struct io_call_10*)inp);
255
            break;
256
 
257
        case SRV_LOCK_SURFACE:
258
            retval = lock_surface((struct io_call_12*)inp);
259
            break;
260
 
261
        case SRV_BLIT_BITMAP:
262
            srv_blit_bitmap( inp[0], inp[1], inp[2],
263
                        inp[3], inp[4], inp[5], inp[6]);
264
*/
265
    };
266
 
267
    return retval;
268
}
269
 
270
 
271
#define PCI_CLASS_REVISION      0x08
272
#define PCI_CLASS_DISPLAY_VGA   0x0300
273
 
274
int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn)
275
{
276
    u16_t vendor, device;
277
    u32_t class;
278
    int   ret = 0;
279
 
280
    vendor   = id & 0xffff;
281
    device   = (id >> 16) & 0xffff;
282
 
283
    if(vendor == 0x1002)
284
    {
285
        class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
286
        class >>= 16;
287
 
288
        if( class == PCI_CLASS_DISPLAY_VGA)
289
            ret = 1;
290
    }
291
    return ret;
292
}
293
 
294
 
295
int seq_printf(struct seq_file *m, const char *f, ...)
296
{
297
//        int ret;
298
//        va_list args;
299
 
300
//        va_start(args, f);
301
//        ret = seq_vprintf(m, f, args);
302
//        va_end(args);
303
 
304
//        return ret;
305
    return 0;
306
}
307
 
308
s64 div64_s64(s64 dividend, s64 divisor)
309
{
310
        s64 quot, t;
311
 
312
        quot = div64_u64(abs64(dividend), abs64(divisor));
313
        t = (dividend ^ divisor) >> 63;
314
 
315
        return (quot ^ t) - t;
316
}
317