Subversion Repositories Kolibri OS

Rev

Rev 2361 | Rev 3037 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2361 Rev 3033
Line 1... Line 1...
1
#include 
1
#include 
2
#include 
-
 
3
#include "i915_drm.h"
2
#include 
4
#include "i915_drv.h"
3
#include "i915_drv.h"
5
#include "intel_drv.h"
4
#include "intel_drv.h"
-
 
5
#include "hmm.h"
6
#include "bitmap.h"
6
#include "bitmap.h"
Line 7... Line 7...
7
 
7
 
-
 
8
#define DRIVER_CAPS_0   HW_BIT_BLIT;
Line 8... Line 9...
8
#define memmove __builtin_memmove
9
#define DRIVER_CAPS_1   0
Line 9... Line -...
9
 
-
 
10
int gem_object_lock(struct drm_i915_gem_object *obj);
10
 
Line 11... Line 11...
11
 
11
struct context *context_map[256];
Line 12... Line -...
12
#define DRIVER_CAPS_0   HW_BIT_BLIT | HW_TEX_BLIT;
-
 
-
 
12
 
Line 13... Line 13...
13
#define DRIVER_CAPS_1   0
13
struct hmm bm_mm;
14
 
14
 
-
 
15
extern struct drm_device *main_device;
-
 
16
 
-
 
17
 
15
extern struct drm_device *main_device;
18
 
16
 
19
void __attribute__((regparm(1))) destroy_bitmap(bitmap_t *bitmap)
17
struct hman bm_man;
20
{
18
 
21
    dma_addr_t *pages = bitmap->obj->allocated_pages;;
19
void __attribute__((regparm(1))) destroy_bitmap(bitmap_t *bitmap)
22
    int i;
Line 20... Line 23...
20
{
23
 
21
    printf("destroy bitmap %d\n", bitmap->handle);
24
    printf("destroy bitmap %d\n", bitmap->handle);
22
    free_handle(&bm_man, bitmap->handle);
25
    free_handle(&bm_mm, bitmap->handle);
Line -... Line 26...
-
 
26
    bitmap->handle = 0;
-
 
27
    bitmap->obj->base.read_domains = I915_GEM_DOMAIN_GTT;
-
 
28
    bitmap->obj->base.write_domain = I915_GEM_DOMAIN_CPU;
-
 
29
 
-
 
30
    mutex_lock(&main_device->struct_mutex);
-
 
31
    drm_gem_object_unreference(&bitmap->obj->base);
-
 
32
    mutex_unlock(&main_device->struct_mutex);
-
 
33
 
23
    bitmap->handle = 0;
34
    if(pages != NULL)
24
    bitmap->obj->base.read_domains = I915_GEM_DOMAIN_GTT;
35
    {
Line -... Line 36...
-
 
36
        for (i = 0; i < bitmap->page_count; i++)
25
    bitmap->obj->base.write_domain = I915_GEM_DOMAIN_CPU;
37
            FreePage(pages[i]);
26
 
38
 
27
    mutex_lock(&main_device->struct_mutex);
39
        free(pages);
Line -... Line 40...
-
 
40
    };
-
 
41
    UserFree(bitmap->uaddr);
-
 
42
    __DestroyObject(bitmap);
-
 
43
};
-
 
44
 
28
    drm_gem_object_unreference(&bitmap->obj->base);
45
 
Line -... Line 46...
-
 
46
static int bitmap_get_pages_gtt(struct drm_i915_gem_object *obj)
-
 
47
{
-
 
48
    int page_count;
-
 
49
 
-
 
50
    /* Get the list of pages out of our struct file.  They'll be pinned
-
 
51
     * at this point until we release them.
-
 
52
     */
29
    mutex_unlock(&main_device->struct_mutex);
53
    page_count = obj->base.size / PAGE_SIZE;
-
 
54
    BUG_ON(obj->allocated_pages == NULL);
-
 
55
    BUG_ON(obj->pages.page != NULL);
-
 
56
 
-
 
57
    obj->pages.page = obj->allocated_pages;
-
 
58
    obj->pages.nents = page_count;
-
 
59
 
-
 
60
 
-
 
61
//   if (obj->tiling_mode != I915_TILING_NONE)
-
 
62
//       i915_gem_object_do_bit_17_swizzle(obj);
-
 
63
 
-
 
64
    return 0;
-
 
65
}
-
 
66
 
-
 
67
static void bitmap_put_pages_gtt(struct drm_i915_gem_object *obj)
-
 
68
{
-
 
69
    int ret, i;
-
 
70
 
-
 
71
    BUG_ON(obj->madv == __I915_MADV_PURGED);
-
 
72
 
-
 
73
    ret = i915_gem_object_set_to_cpu_domain(obj, true);
-
 
74
    if (ret) {
-
 
75
        /* In the event of a disaster, abandon all caches and
-
 
76
         * hope for the best.
-
 
77
         */
-
 
78
        WARN_ON(ret != -EIO);
-
 
79
        i915_gem_clflush_object(obj);
-
 
80
        obj->base.read_domains = obj->base.write_domain = I915_GEM_DOMAIN_CPU;
-
 
81
    }
-
 
82
 
-
 
83
    if (obj->madv == I915_MADV_DONTNEED)
-
 
84
        obj->dirty = 0;
-
 
85
 
-
 
86
    obj->dirty = 0;
-
 
87
}
-
 
88
 
-
 
89
static const struct drm_i915_gem_object_ops bitmap_object_ops = {
-
 
90
    .get_pages = bitmap_get_pages_gtt,
-
 
91
    .put_pages = bitmap_put_pages_gtt,
-
 
92
};
-
 
93
 
-
 
94
 
-
 
95
 
-
 
96
#if 0
-
 
97
struct  io_call_10         /*     SRV_CREATE_SURFACE    */
30
 
98
{
Line -... Line 99...
-
 
99
    u32     handle;       // ignored
Line 31... Line 100...
31
    __DestroyObject(bitmap);
100
    void   *data;         // ignored
32
};
101
 
33
 
102
    u32     width;
Line 34... Line 103...
34
int init_bitmaps()
103
    u32     height;
35
{
104
    u32     pitch;        // ignored
36
    int ret;
105
 
37
 
106
    u32     max_width;
38
    ret = init_hman(&bm_man, 1024);
107
    u32     max_height;
39
 
108
    u32     format;       // reserved mbz
40
    return ret;
109
};
-
 
110
 
-
 
111
#endif
-
 
112
 
-
 
113
int create_surface(struct drm_device *dev, struct io_call_10 *pbitmap)
Line 41... Line 114...
41
};
114
{
Line 42... Line 115...
42
 
115
    struct drm_i915_gem_object *obj;
43
 
116
 
Line 44... Line 117...
44
int create_surface(struct io_call_10 *pbitmap)
117
    bitmap_t   *bitmap;
45
{
118
    u32         handle;
Line 46... Line -...
46
    struct drm_i915_gem_object *obj;
-
 
47
 
119
    u32         width, max_width;
48
    bitmap_t   *bitmap;
120
    u32         height, max_height;
Line -... Line 121...
-
 
121
    u32         size,  max_size;
49
    u32         handle;
122
    u32         pitch, max_pitch;
50
    u32         width, max_width;
123
    void       *uaddr;
51
    u32         height, max_height;
124
    dma_addr_t *pages;
52
    u32         size,  max_size;
125
    u32         page_count;
Line 81... Line 154...
81
 
154
 
Line 82... Line 155...
82
    max_width  = (pbitmap->max_width ==0) ? width  : pbitmap->max_width;
155
    max_width  = (pbitmap->max_width ==0) ? width  : pbitmap->max_width;
83
    max_height = (pbitmap->max_height==0) ? height : pbitmap->max_height;
156
    max_height = (pbitmap->max_height==0) ? height : pbitmap->max_height;
Line 84... Line 157...
84
 
157
 
85
    handle = alloc_handle(&bm_man);
158
    handle = alloc_handle(&bm_mm);
Line 86... Line 159...
86
//    printf("%s %d\n",__FUNCTION__, handle);
159
//    printf("%s %d\n",__FUNCTION__, handle);
87
 
160
 
Line 88... Line 161...
88
    if(handle == 0)
161
    if(handle == 0)
89
        goto err1;
162
        goto err1;
90
 
163
 
91
    bitmap = CreateObject(GetPid(), sizeof(*bitmap));
164
    bitmap = CreateObject(GetPid(), sizeof(*bitmap));
Line 92... Line 165...
92
//    printf("bitmap %x\n", bitmap);
165
//    printf("bitmap %x\n", bitmap);
93
    if( bitmap == NULL)
166
    if( bitmap == NULL)
94
        goto err1;
167
        goto err2;
Line 95... Line -...
95
 
-
 
96
    bitmap->handle = handle;
168
 
Line 97... Line 169...
97
    bitmap->header.destroy = destroy_bitmap;
169
    bitmap->handle = handle;
98
    bitmap->obj    = NULL;
-
 
99
 
170
    bitmap->header.destroy = destroy_bitmap;
Line 100... Line 171...
100
 
171
    bitmap->obj    = NULL;
Line 101... Line -...
101
    hman_set_data(&bm_man, handle, bitmap);
-
 
102
 
-
 
103
    pitch = ALIGN(width*4,64);
-
 
104
 
-
 
105
    size =  roundup(pitch*height, PAGE_SIZE);
-
 
106
 
-
 
107
//    printf("pitch %d size %d\n", pitch, size);
-
 
108
 
-
 
109
    obj = i915_gem_alloc_object(main_device, size);
172
 
110
    if (obj == NULL)
173
    hmm_set_data(&bm_mm, handle, bitmap);
Line -... Line 174...
-
 
174
 
-
 
175
    pitch = ALIGN(width*4,64);
111
        goto err2;
176
    size =  roundup(pitch*height, PAGE_SIZE);
112
 
177
 
113
    ret = i915_gem_object_pin(obj, 4096, true);
178
//    printf("pitch %d size %d\n", pitch, size);
114
    if (ret)
179
 
115
        goto err3;
180
    max_pitch = ALIGN(max_width*4,64);
116
 
181
    max_size =  roundup(max_pitch*max_height, PAGE_SIZE);
-
 
182
 
117
    max_pitch = ALIGN(max_width*4,64);
183
//    printf("max_pitch %d max_size %d\n", max_pitch, max_size);
Line 118... Line 184...
118
    max_size =  roundup(max_pitch*max_height, PAGE_SIZE);
184
 
-
 
185
    uaddr = UserAlloc(max_size);
Line 119... Line -...
119
 
-
 
120
    uaddr = UserAlloc(max_size);
186
    if( uaddr == NULL)
121
    if( uaddr == NULL)
187
        goto err3;
122
        goto err4;
188
    else
Line 123... Line 189...
123
    else
189
    {
124
    {
190
        u32           max_count;
-
 
191
        dma_addr_t    page;
-
 
192
        char *vaddr = uaddr;
-
 
193
 
-
 
194
        page_count = size/PAGE_SIZE;
-
 
195
        max_count = max_size/PAGE_SIZE;
125
        u32_t *src, *dst;
196
 
-
 
197
        pages = kzalloc(max_count*sizeof(dma_addr_t), 0);
-
 
198
        if( pages == NULL)
-
 
199
            goto err4;
126
        u32 count, max_count;
200
 
-
 
201
        for(i = 0; i < page_count; i++, vaddr+= PAGE_SIZE)
-
 
202
        {
-
 
203
            page = AllocPage();
127
 
204
            if ( page == 0 )
-
 
205
                goto err4;
-
 
206
            pages[i] = page;
-
 
207
 
-
 
208
            MapPage(vaddr, page, 0x207);        //map as shared page
128
#define page_tabs  0xFDC00000      /* really dirty hack */
209
        };
129
 
210
        bitmap->page_count = page_count;
-
 
211
        bitmap->max_count  = max_count;
Line 130... Line 212...
130
        src =  (u32_t*)obj->pages;
212
    };
Line 131... Line 213...
131
        dst =  &((u32_t*)page_tabs)[(u32_t)uaddr >> 12];
213
 
132
        count = size/4096;
214
    obj = i915_gem_alloc_object(dev, size);
Line 164... Line 246...
164
            __FUNCTION__, handle, pitch, obj->gtt_offset, uaddr);
246
            __FUNCTION__, handle, pitch, obj->gtt_offset, uaddr);
165
 
247
 
Line 166... Line 248...
166
    return 0;
248
    return 0;
Line -... Line 249...
-
 
249
 
-
 
250
err5:
-
 
251
    mutex_lock(&dev->struct_mutex);
-
 
252
    drm_gem_object_unreference(&obj->base);
-
 
253
    mutex_unlock(&dev->struct_mutex);
167
 
254
 
-
 
255
err4:
168
err4:
256
    while (i--)
-
 
257
        FreePage(pages[i]);
-
 
258
    free(pages);
-
 
259
    UserFree(uaddr);
169
    i915_gem_object_unpin(obj);
260
 
170
err3:
-
 
171
    drm_gem_object_unreference(&obj->base);
-
 
172
err2:
-
 
173
    free_handle(&bm_man, handle);
261
err3:
-
 
262
    __DestroyObject(bitmap);
-
 
263
err2:
174
    __DestroyObject(bitmap);
264
    free_handle(&bm_mm, handle);
175
err1:
265
err1:
176
    return -1;
-
 
177
 
266
    return -1;
Line 178... Line 267...
178
};
267
};
179
 
268
 
180
 
269
 
Line 181... Line -...
181
int lock_surface(struct io_call_12 *pbitmap)
-
 
182
{
-
 
183
    int ret;
270
int lock_surface(struct io_call_12 *pbitmap)
Line 184... Line 271...
184
 
271
{
185
    drm_i915_private_t *dev_priv = main_device->dev_private;
272
    int ret;
Line 186... Line 273...
186
 
273
 
Line 187... Line 274...
187
    bitmap_t  *bitmap;
274
    bitmap_t  *bitmap;
188
 
275
 
Line 189... Line 276...
189
    if(unlikely(pbitmap->handle == 0))
276
    if(unlikely(pbitmap->handle == 0))
-
 
277
        return -1;
190
        return -1;
278
 
191
 
279
    bitmap = (bitmap_t*)hmm_get_data(&bm_mm, pbitmap->handle);
192
    bitmap = (bitmap_t*)hman_get_data(&bm_man, pbitmap->handle);
280
 
193
 
281
    if(unlikely(bitmap==NULL))
Line 210... Line 298...
210
    return 0;
298
    return 0;
211
};
299
};
Line 212... Line -...
212
 
-
 
213
 
-
 
214
int init_hman(struct hman *man, u32 count)
-
 
Line 215... Line -...
215
{
-
 
-
 
300
 
216
    u32* data;
301
 
217
 
302
 
218
    data = malloc(count*sizeof(u32*));
303
 
Line 219... Line 304...
219
    if(data)
304
int init_bitmaps()
220
    {
-
 
221
        int i;
-
 
222
 
-
 
223
        for(i=0;i < count-1;)
-
 
224
            data[i] = ++i;
-
 
225
        data[i] = 0;
-
 
226
 
-
 
Line 227... Line -...
227
        man->table = data;
-
 
228
        man->next  = 0;
-
 
229
        man->avail = count;
305
{
230
        man->count = count;
306
    int ret;
Line 231... Line -...
231
 
-
 
232
        return 0;
-
 
233
    };
-
 
Line 234... Line -...
234
    return -ENOMEM;
-
 
235
};
-
 
236
 
-
 
237
u32  alloc_handle(struct hman *man)
-
 
238
{
-
 
239
    u32 handle = 0;
-
 
240
 
-
 
241
    if(man->avail)
-
 
242
    {
-
 
Line 243... Line 307...
243
        handle = man->next;
307
 
244
        man->next = man->table[handle];
308
    ret = init_hmm(&bm_mm, 1024);
245
        man->avail--;
309
 
246
        handle++;
-
 
247
    }
-
 
Line 248... Line 310...
248
    return handle;
310
    return ret;
249
};
311
};
250
 
312
 
251
int free_handle(struct hman *man, u32 handle)
313
 
252
{
314
 
253
    int ret = -1;
315
int get_driver_caps(hwcaps_t *caps)
254
 
-
 
Line -... Line 316...
-
 
316
{
-
 
317
    int ret = 0;
-
 
318
 
255
    handle--;
319
    switch(caps->idx)
-
 
320
    {
-
 
321
        case 0:
256
 
322
            caps->opt[0] = DRIVER_CAPS_0;
-
 
323
            caps->opt[1] = DRIVER_CAPS_1;
-
 
324
            break;
-
 
325
 
Line 257... Line 326...
257
    if(handle < man->count)
326
        case 1:
258
    {
327
            caps->cap1.max_tex_width  = 4096;
259
        man->table[handle] = man->next;
328
            caps->cap1.max_tex_height = 4096;
Line 260... Line -...
260
        man->next = handle;
-
 
261
        man->avail++;
-
 
262
        ret = 0;
-
 
263
    };
329
            break;
264
 
-
 
Line 265... Line 330...
265
    return ret;
330
        default:
-
 
331
            ret = 1;
-
 
332
    };
Line 266... Line 333...
266
};
333
    caps->idx = 1;
267
 
-
 
268
 
-
 
269
void *drm_intel_bo_map(struct drm_i915_gem_object *obj, int write_enable)
-
 
270
{
-
 
271
    u8 *kaddr;
334
    return ret;
272
 
-
 
273
    kaddr = AllocKernelSpace(obj->base.size);
-
 
Line 274... Line -...
274
    if( kaddr != NULL)
-
 
275
    {
-
 
276
        u32_t *src = (u32_t*)obj->pages;
-
 
277
        u32_t *dst = &((u32_t*)page_tabs)[(u32_t)kaddr >> 12];
-
 
278
 
-
 
279
        u32 count  = obj->base.size/4096;
-
 
Line -... Line 335...
-
 
335
}
Line 280... Line 336...
280
 
336
 
281
        while(count--)
337
 
282
        {
338
void __attribute__((regparm(1))) destroy_context(struct context *context)
283
            *dst++ = (0xFFFFF000 & *src++) | 0x003 ;
339
{
-
 
340
    printf("destroy context %x\n", context);
284
        };
341
 
Line 285... Line 342...
285
        return kaddr;
342
    context_map[context->slot] = NULL;
286
    };
-
 
287
    return NULL;
-
 
Line 288... Line -...
288
}
-
 
289
 
343
 
290
void destroy_gem_object(uint32_t handle)
-
 
291
{
-
 
292
    struct drm_i915_gem_object *obj = (void*)handle;
344
    mutex_lock(&main_device->struct_mutex);
293
    drm_gem_object_unreference(&obj->base);
-
 
294
 
-
 
Line -... Line 345...
-
 
345
    drm_gem_object_unreference(&context->obj->base);
295
};
346
    mutex_unlock(&main_device->struct_mutex);
-
 
347
 
296
 
348
    __DestroyObject(context);
297
 
349
};
298
void write_gem_object(uint32_t handle, u32 offset, u32 size, u8* src)
-
 
299
{
350
 
300
    struct drm_i915_gem_object *obj = (void*)handle;
-
 
Line -... Line 351...
-
 
351
 
-
 
352
#define CURRENT_TASK             (0x80003000)
Line 301... Line 353...
301
    u8    *dst;
353
 
302
    int    ret;
-
 
-
 
354
struct context *get_context(struct drm_device *dev)
303
 
355
{
304
    ret = i915_gem_object_pin(obj, 4096, true);
-
 
Line 305... Line 356...
305
    if (ret)
356
    struct context *context;
306
        return;
-
 
307
 
357
    struct io_call_10 io_10;
308
    dst = drm_intel_bo_map(obj, true);
358
    int    slot = *((u8*)CURRENT_TASK);
309
    if( dst != NULL )
359
    int    ret;
310
    {
-
 
Line 311... Line -...
311
        memmove(dst+offset, src, size);
-
 
312
        FreeKernelSpace(dst);
-
 
313
    };
360
 
314
};
-
 
315
 
361
    context = context_map[slot];
316
u32 get_buffer_offset(uint32_t handle)
362
 
317
{
363
    if( context != NULL)
318
    struct drm_i915_gem_object *obj = (void*)handle;
-
 
319
 
-
 
320
    return obj->gtt_offset;
-