Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3032 → Rev 3033

/drivers/video/drm/i915/bitmap.c
1,26 → 1,29
 
#include <drmP.h>
#include <drm.h>
#include "i915_drm.h"
#include <drm/drmP.h>
#include <drm/i915_drm.h>
#include "i915_drv.h"
#include "intel_drv.h"
#include "hmm.h"
#include "bitmap.h"
 
#define memmove __builtin_memmove
#define DRIVER_CAPS_0 HW_BIT_BLIT;
#define DRIVER_CAPS_1 0
 
int gem_object_lock(struct drm_i915_gem_object *obj);
struct context *context_map[256];
 
#define DRIVER_CAPS_0 HW_BIT_BLIT | HW_TEX_BLIT;
#define DRIVER_CAPS_1 0
struct hmm bm_mm;
 
extern struct drm_device *main_device;
 
struct hman bm_man;
 
 
void __attribute__((regparm(1))) destroy_bitmap(bitmap_t *bitmap)
{
dma_addr_t *pages = bitmap->obj->allocated_pages;;
int i;
 
printf("destroy bitmap %d\n", bitmap->handle);
free_handle(&bm_man, bitmap->handle);
free_handle(&bm_mm, bitmap->handle);
bitmap->handle = 0;
bitmap->obj->base.read_domains = I915_GEM_DOMAIN_GTT;
bitmap->obj->base.write_domain = I915_GEM_DOMAIN_CPU;
29,21 → 32,87
drm_gem_object_unreference(&bitmap->obj->base);
mutex_unlock(&main_device->struct_mutex);
 
if(pages != NULL)
{
for (i = 0; i < bitmap->page_count; i++)
FreePage(pages[i]);
 
free(pages);
};
UserFree(bitmap->uaddr);
__DestroyObject(bitmap);
};
 
int init_bitmaps()
 
static int bitmap_get_pages_gtt(struct drm_i915_gem_object *obj)
{
int ret;
int page_count;
 
ret = init_hman(&bm_man, 1024);
/* Get the list of pages out of our struct file. They'll be pinned
* at this point until we release them.
*/
page_count = obj->base.size / PAGE_SIZE;
BUG_ON(obj->allocated_pages == NULL);
BUG_ON(obj->pages.page != NULL);
 
return ret;
obj->pages.page = obj->allocated_pages;
obj->pages.nents = page_count;
 
 
// if (obj->tiling_mode != I915_TILING_NONE)
// i915_gem_object_do_bit_17_swizzle(obj);
 
return 0;
}
 
static void bitmap_put_pages_gtt(struct drm_i915_gem_object *obj)
{
int ret, i;
 
BUG_ON(obj->madv == __I915_MADV_PURGED);
 
ret = i915_gem_object_set_to_cpu_domain(obj, true);
if (ret) {
/* In the event of a disaster, abandon all caches and
* hope for the best.
*/
WARN_ON(ret != -EIO);
i915_gem_clflush_object(obj);
obj->base.read_domains = obj->base.write_domain = I915_GEM_DOMAIN_CPU;
}
 
if (obj->madv == I915_MADV_DONTNEED)
obj->dirty = 0;
 
obj->dirty = 0;
}
 
static const struct drm_i915_gem_object_ops bitmap_object_ops = {
.get_pages = bitmap_get_pages_gtt,
.put_pages = bitmap_put_pages_gtt,
};
 
 
int create_surface(struct io_call_10 *pbitmap)
 
#if 0
struct io_call_10 /* SRV_CREATE_SURFACE */
{
u32 handle; // ignored
void *data; // ignored
 
u32 width;
u32 height;
u32 pitch; // ignored
 
u32 max_width;
u32 max_height;
u32 format; // reserved mbz
};
 
#endif
 
int create_surface(struct drm_device *dev, struct io_call_10 *pbitmap)
{
struct drm_i915_gem_object *obj;
 
bitmap_t *bitmap;
53,7 → 122,11
u32 size, max_size;
u32 pitch, max_pitch;
void *uaddr;
dma_addr_t *pages;
u32 page_count;
 
int i;
 
int ret;
 
pbitmap->handle = 0;
62,10 → 135,10
width = pbitmap->width;
height = pbitmap->height;
 
/*
if((width==0)||(height==0)||(width>4096)||(height>4096))
goto err1;
 
/*
if( ((pbitmap->max_width !=0 ) &&
(pbitmap->max_width < width)) ||
(pbitmap->max_width > 4096) )
83,7 → 156,7
max_width = (pbitmap->max_width ==0) ? width : pbitmap->max_width;
max_height = (pbitmap->max_height==0) ? height : pbitmap->max_height;
 
handle = alloc_handle(&bm_man);
handle = alloc_handle(&bm_mm);
// printf("%s %d\n",__FUNCTION__, handle);
 
if(handle == 0)
92,55 → 165,64
bitmap = CreateObject(GetPid(), sizeof(*bitmap));
// printf("bitmap %x\n", bitmap);
if( bitmap == NULL)
goto err1;
goto err2;
 
bitmap->handle = handle;
bitmap->header.destroy = destroy_bitmap;
bitmap->obj = NULL;
 
hmm_set_data(&bm_mm, handle, bitmap);
 
hman_set_data(&bm_man, handle, bitmap);
 
pitch = ALIGN(width*4,64);
 
size = roundup(pitch*height, PAGE_SIZE);
 
// printf("pitch %d size %d\n", pitch, size);
 
obj = i915_gem_alloc_object(main_device, size);
if (obj == NULL)
goto err2;
 
ret = i915_gem_object_pin(obj, 4096, true);
if (ret)
goto err3;
 
max_pitch = ALIGN(max_width*4,64);
max_size = roundup(max_pitch*max_height, PAGE_SIZE);
 
// printf("max_pitch %d max_size %d\n", max_pitch, max_size);
 
uaddr = UserAlloc(max_size);
if( uaddr == NULL)
goto err4;
goto err3;
else
{
u32_t *src, *dst;
u32 count, max_count;
u32 max_count;
dma_addr_t page;
char *vaddr = uaddr;
 
#define page_tabs 0xFDC00000 /* really dirty hack */
page_count = size/PAGE_SIZE;
max_count = max_size/PAGE_SIZE;
 
src = (u32_t*)obj->pages;
dst = &((u32_t*)page_tabs)[(u32_t)uaddr >> 12];
count = size/4096;
max_count = max_size/4096 - count;
pages = kzalloc(max_count*sizeof(dma_addr_t), 0);
if( pages == NULL)
goto err4;
 
while(count--)
for(i = 0; i < page_count; i++, vaddr+= PAGE_SIZE)
{
*dst++ = (0xFFFFF000 & *src++) | 0x207 ; // map as shared page
page = AllocPage();
if ( page == 0 )
goto err4;
pages[i] = page;
 
MapPage(vaddr, page, 0x207); //map as shared page
};
while(max_count--)
*dst++ = 0; // cleanup unused space
}
bitmap->page_count = page_count;
bitmap->max_count = max_count;
};
 
obj = i915_gem_alloc_object(dev, size);
if (obj == NULL)
goto err4;
 
obj->ops = &bitmap_object_ops;
obj->allocated_pages = pages;
 
ret = i915_gem_object_pin(obj, PAGE_SIZE, true,true);
if (ret)
goto err5;
 
obj->mapped = uaddr ;
 
bitmap->handle = handle;
166,16 → 248,23
 
return 0;
 
err5:
mutex_lock(&dev->struct_mutex);
drm_gem_object_unreference(&obj->base);
mutex_unlock(&dev->struct_mutex);
 
err4:
i915_gem_object_unpin(obj);
while (i--)
FreePage(pages[i]);
free(pages);
UserFree(uaddr);
 
err3:
drm_gem_object_unreference(&obj->base);
__DestroyObject(bitmap);
err2:
free_handle(&bm_man, handle);
__DestroyObject(bitmap);
free_handle(&bm_mm, handle);
err1:
return -1;
 
};
 
 
183,19 → 272,18
{
int ret;
 
drm_i915_private_t *dev_priv = main_device->dev_private;
 
bitmap_t *bitmap;
 
if(unlikely(pbitmap->handle == 0))
return -1;
 
bitmap = (bitmap_t*)hman_get_data(&bm_man, pbitmap->handle);
bitmap = (bitmap_t*)hmm_get_data(&bm_mm, pbitmap->handle);
 
if(unlikely(bitmap==NULL))
return -1;
 
ret = gem_object_lock(bitmap->obj);
ret = i915_gem_object_set_to_cpu_domain(bitmap->obj, true);
 
if(ret !=0 )
{
pbitmap->data = NULL;
212,136 → 300,91
};
 
 
int init_hman(struct hman *man, u32 count)
{
u32* data;
 
data = malloc(count*sizeof(u32*));
if(data)
 
int init_bitmaps()
{
int i;
int ret;
 
for(i=0;i < count-1;)
data[i] = ++i;
data[i] = 0;
ret = init_hmm(&bm_mm, 1024);
 
man->table = data;
man->next = 0;
man->avail = count;
man->count = count;
 
return 0;
return ret;
};
return -ENOMEM;
};
 
u32 alloc_handle(struct hman *man)
{
u32 handle = 0;
 
if(man->avail)
 
int get_driver_caps(hwcaps_t *caps)
{
handle = man->next;
man->next = man->table[handle];
man->avail--;
handle++;
}
return handle;
};
int ret = 0;
 
int free_handle(struct hman *man, u32 handle)
switch(caps->idx)
{
int ret = -1;
case 0:
caps->opt[0] = DRIVER_CAPS_0;
caps->opt[1] = DRIVER_CAPS_1;
break;
 
handle--;
 
if(handle < man->count)
{
man->table[handle] = man->next;
man->next = handle;
man->avail++;
ret = 0;
case 1:
caps->cap1.max_tex_width = 4096;
caps->cap1.max_tex_height = 4096;
break;
default:
ret = 1;
};
 
caps->idx = 1;
return ret;
};
}
 
 
void *drm_intel_bo_map(struct drm_i915_gem_object *obj, int write_enable)
void __attribute__((regparm(1))) destroy_context(struct context *context)
{
u8 *kaddr;
printf("destroy context %x\n", context);
 
kaddr = AllocKernelSpace(obj->base.size);
if( kaddr != NULL)
{
u32_t *src = (u32_t*)obj->pages;
u32_t *dst = &((u32_t*)page_tabs)[(u32_t)kaddr >> 12];
context_map[context->slot] = NULL;
 
u32 count = obj->base.size/4096;
mutex_lock(&main_device->struct_mutex);
drm_gem_object_unreference(&context->obj->base);
mutex_unlock(&main_device->struct_mutex);
 
while(count--)
{
*dst++ = (0xFFFFF000 & *src++) | 0x003 ;
__DestroyObject(context);
};
return kaddr;
};
return NULL;
}
 
void destroy_gem_object(uint32_t handle)
{
struct drm_i915_gem_object *obj = (void*)handle;
drm_gem_object_unreference(&obj->base);
 
};
#define CURRENT_TASK (0x80003000)
 
 
void write_gem_object(uint32_t handle, u32 offset, u32 size, u8* src)
struct context *get_context(struct drm_device *dev)
{
struct drm_i915_gem_object *obj = (void*)handle;
u8 *dst;
struct context *context;
struct io_call_10 io_10;
int slot = *((u8*)CURRENT_TASK);
int ret;
 
ret = i915_gem_object_pin(obj, 4096, true);
if (ret)
return;
context = context_map[slot];
 
dst = drm_intel_bo_map(obj, true);
if( dst != NULL )
{
memmove(dst+offset, src, size);
FreeKernelSpace(dst);
};
};
if( context != NULL)
return context;
 
u32 get_buffer_offset(uint32_t handle)
context = CreateObject(GetPid(), sizeof(*context));
printf("context %x\n", context);
if( context != NULL)
{
struct drm_i915_gem_object *obj = (void*)handle;
drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_i915_gem_object *obj;
 
return obj->gtt_offset;
};
obj = i915_gem_alloc_object(dev, 4096);
i915_gem_object_pin(obj, 4096, true, true);
 
context->obj = obj;
context->cmd_buffer = MapIoMem((addr_t)obj->pages.page[0], 4096, PG_SW|PG_NOCACHE);
context->cmd_offset = obj->gtt_offset;
 
int get_driver_caps(hwcaps_t *caps)
{
int ret = 0;
ENTER();
context->header.destroy = destroy_context;
context->mask = NULL;
context->seqno = 0;
context->slot = slot;
 
switch(caps->idx)
{
case 0:
caps->opt[0] = DRIVER_CAPS_0;
caps->opt[1] = DRIVER_CAPS_1;
break;
 
case 1:
caps->cap1.max_tex_width = 4096;
caps->cap1.max_tex_height = 4096;
break;
default:
ret = 1;
context_map[slot] = context;
};
caps->idx = 1;
return ret;
}
return context;
};