mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[kvmfr] added the ability to obtain a dmabuf of the ivshmem memory
This is to enable the ability to use dri3 to create dmabuf backed pixmaps directly.
This commit is contained in:
52
module/test.c
Normal file
52
module/test.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "kvmfr.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd = open("/dev/kvmfr0", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned long size = ioctl(fd, KVMFR_DMABUF_GETSIZE , 0);
|
||||
unsigned long alignment = ioctl(fd, KVMFR_DMABUF_GETALIGN, 0);
|
||||
|
||||
printf("Size: %lu MiB, Alignment: %lu MiB\n", size / 1024 / 1024, alignment / 1024 / 1024);
|
||||
|
||||
struct kvmfr_dmabuf_create create =
|
||||
{
|
||||
.flags = KVMFR_DMABUF_FLAG_CLOEXEC,
|
||||
.offset = 0x0,
|
||||
.size = size,
|
||||
};
|
||||
int dmaFd = ioctl(fd, KVMFR_DMABUF_CREATE, &create);
|
||||
if (dmaFd < 0)
|
||||
{
|
||||
perror("ioctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void * mem = mmap(NULL, create.size, PROT_READ | PROT_WRITE, MAP_SHARED, dmaFd, 0);
|
||||
if (!mem)
|
||||
{
|
||||
perror("mmap");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(mem, 0xAA, create.size);
|
||||
munmap(mem, create.size);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user