1
1

183 строки
4.5 KiB
C

/*
* (c) 2010, SWD Embedded Systems Limited, http://www.kpda.ru
*/
#include <string.h>
#include <stdlib.h>
#include "vesabios.h"
/*
* Since this driver is unaccelerated, everything execpt the main display
* is allocated from system RAM, since access to frame buffer RAM is
* generally *much* slower.
*/
int
devg_get_memfuncs(disp_adapter_t *adp, disp_memfuncs_t *funcs, int tabsize)
{
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
init, vesa_mem_init, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
fini, vesa_mem_fini, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
module_info, vesa_module_info, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
reset, vesa_mem_reset, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
alloc_surface, vesa_alloc_surface, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
free_surface, vesa_free_surface, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
mem_avail, vesa_mem_avail, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
query_apertures, vesa_query_apertures, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
query_surface, vesa_query_surface, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
get_alloc_info, vesa_get_alloc_info, tabsize);
DISP_ADD_FUNC(disp_memfuncs_t, funcs,
get_alloc_layer_info, vesa_get_alloc_layer_info, tabsize);
return 0;
}
int
vesa_mem_init(disp_adapter_t *adapter, char *optstring)
{
vb_context_t *vb = adapter->ms_ctx;
vb->visible_allocated = 0;
return 0;
}
void
vesa_mem_fini(disp_adapter_t *adapter)
{
}
int
vesa_mem_reset(disp_adapter_t *adapter, disp_surface_t *surf)
{
vb_context_t *vb = adapter->ms_ctx;
vb->visible_allocated = 0;
return 0;
}
disp_surface_t *
vesa_alloc_surface(disp_adapter_t *adapter,
int width, int height, unsigned format, unsigned flags, unsigned user_flags)
{
vb_context_t *vb = adapter->ms_ctx;
disp_surface_t *surf = NULL;
if (vb->visible.height != 0 && (flags & DISP_SURFACE_DISPLAYABLE)) {
/*
* We cannot move the display offset, so there can only
* be a single displayable surface, at offset 0
*/
if(vb->visible_allocated) {
return NULL;
}
vb->visible_allocated = 1;
vb->visible.size = sizeof(vb->visible);
return &vb->visible;
}
return surf;
}
int
vesa_free_surface(disp_adapter_t *adapter, disp_surface_t *surf)
{
vb_context_t *vb = adapter->ms_ctx;
if (surf == &vb->visible) {
vb->visible_allocated = 0;
return 0;
}
disp_freemem(surf->vidptr, surf->height * surf->stride);
free(surf);
return 0;
}
unsigned long
vesa_mem_avail(disp_adapter_t *adapter, unsigned flags)
{
return 0;
}
int
vesa_query_apertures(disp_adapter_t *adp, disp_aperture_t *ap)
{
vb_context_t *vb_ctx = adp->ms_ctx;
ap->base = vb_ctx->vidbase;
ap->size = vb_ctx->vidsize;
ap->flags = DISP_APER_NOCACHE;
return 1;
}
/*
* return the aperture within which the memory surface resides, and
* the physical offset of the memory within that aperture
*/
int
vesa_query_surface(disp_adapter_t *adp,
disp_surface_t *surf, disp_surface_info_t *info)
{
info->aperture_index = 0;
info->offset = surf->offset;
return 0;
}
/*
* If a client of the driver wants to allocate memory itself,
* it must allocate it in accordance with the parameters returned by
* this process. Since this memory will not be coming from
* video memory, we must check the flags accordingly.
*/
int
vesa_get_alloc_info(disp_adapter_t *adp,
int width, int height, unsigned format,
unsigned flags, unsigned user_flags, disp_alloc_info_t *info)
{
flags &= DISP_SURFACE_CAPS_MASK;
if (flags & ~(DISP_SURFACE_CPU_LINEAR_READABLE |
DISP_SURFACE_CPU_LINEAR_WRITEABLE|
DISP_SURFACE_PAGE_ALIGNED|DISP_SURFACE_PHYS_CONTIG))
return -1;
info->start_align = 4;
info->end_align = 1;
info->min_stride = width * DISP_BYTES_PER_PIXEL(format);
info->max_stride = ~0;
info->stride_gran = 4;
info->map_flags = 0;
info->prot_flags = DISP_PROT_READ | DISP_PROT_WRITE;
info->surface_flags = DISP_SURFACE_CPU_LINEAR_READABLE |
DISP_SURFACE_CPU_LINEAR_WRITEABLE | DISP_SURFACE_DRIVER_NOT_OWNER;
return 0;
}
int
vesa_get_alloc_layer_info(disp_adapter_t *adp, int dispno[], int layer_idx[],
int nlayers, unsigned format, int surface_index, int width, int height,
unsigned sflags, unsigned hint_flags, disp_alloc_info_t *info)
{
/* No layers */
return -1;
}