/* Definitions for front buffer */ #include #include #include #include #include #include #include "screen.h" #include "object.h" /* Global variables */ int screen_width; int screen_height; int screen_bpp; int screen_offset; int screen_pitch; int viewport_x=32, viewport_y=32; int viewport_w=512, viewport_h=512; int drm_fd = -1; struct nouveau_device *dev = NULL; /* Functions */ int screen_open(int width, int height, int bpp) { int ret; drm_fd = drmOpen("nouveau", 0); if (drm_fd < 0) { drmError(drm_fd, __func__); fprintf(stderr, "failed to open drm\n"); return 1; } ret = nouveau_device_open_existing(&dev, 0, drm_fd, 0); if (ret) { screen_close(); return 1; } printf("screen: chipset: 0x%08x\n", dev->chipset); printf("screen: vm_vram_base: 0x%" PRIu64 "\n", dev->vm_vram_base); printf("screen: vm_vram_size: %d MB\n", (int) (dev->vm_vram_size >> 20)); printf("screen: vm_gart_size: %d MB\n", (int) (dev->vm_gart_size >> 20)); screen_width = width; screen_height = height; screen_bpp = bpp; /* NOTE: find vt console fb in dmesg log: [ 9.435846] [drm] nouveau 0000:01:00.0: allocated 1680x1050 fb: 0x49000, bo ffff88007c0e8600 */ screen_offset = 0x49000; screen_pitch = screen_width*(screen_bpp/8); if ((screen_pitch & 255)!=0) { screen_pitch = (screen_pitch | 255)+1; /* Align on 256 bytes boundary */ } printf("screen: %dx%dx%d, pitch=%d, offset=0x%08x\n", screen_width, screen_height, screen_bpp, screen_pitch, screen_offset ); /* TODO: if running with X, try to find front buffer offset and resolution */ return 0; } void screen_close(void) { if (dev) { nouveau_device_close(&dev); dev = NULL; } if (drm_fd>=0) { drmClose(drm_fd); drm_fd = -1; } } struct nouveau_bo *screen_allocmem(int size) { struct nouveau_bo *bo = NULL; uint32_t flags = NOUVEAU_BO_MAP; int ret; ret = nouveau_bo_new(dev, flags, 0x100, size, &bo); if (ret) return NULL; ret = nouveau_bo_map(bo, NOUVEAU_BO_WR); if (ret) { printf("screen: map failed: %d\n", ret); nouveau_bo_ref(NULL, &bo); return NULL; } return bo; }