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
 
</