Subversion Repositories Kolibri OS

Rev

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