Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fp-time
Browse files Browse the repository at this point in the history
  • Loading branch information
sshane committed Aug 23, 2023
2 parents 2365588 + e7c42fd commit 94fb711
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ repos:
- id: check-ast
- id: check-yaml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
rev: v1.5.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.0.285
hooks:
- id: ruff
- repo: local
Expand Down
33 changes: 18 additions & 15 deletions visionipc/visionbuf_ion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,35 @@
#define DEVICE_PAGE_SIZE_CL 4096
#define PADDING_CL 0

static int ion_fd = -1;
static void ion_init() {
if (ion_fd == -1) {
ion_fd = open("/dev/ion", O_RDWR | O_NONBLOCK);
struct IonFileHandle {
IonFileHandle() {
fd = open("/dev/ion", O_RDWR | O_NONBLOCK);
assert(fd >= 0);
}
~IonFileHandle() {
close(fd);
}
int fd = -1;
};

int ion_fd() {
static IonFileHandle fh;
return fh.fd;
}

void VisionBuf::allocate(size_t length) {
int err;

ion_init();

struct ion_allocation_data ion_alloc = {0};
ion_alloc.len = length + PADDING_CL + sizeof(uint64_t);
ion_alloc.align = 4096;
ion_alloc.heap_id_mask = 1 << ION_IOMMU_HEAP_ID;
ion_alloc.flags = ION_FLAG_CACHED;

err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc));
int err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_ALLOC, &ion_alloc));
assert(err == 0);

struct ion_fd_data ion_fd_data = {0};
ion_fd_data.handle = ion_alloc.handle;
err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_SHARE, &ion_fd_data));
err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_SHARE, &ion_fd_data));
assert(err == 0);

void *mmap_addr = mmap(NULL, ion_alloc.len,
Expand All @@ -85,12 +90,10 @@ void VisionBuf::import(){
int err;
assert(this->fd >= 0);

ion_init();

// Get handle
struct ion_fd_data fd_data = {0};
fd_data.fd = this->fd;
err = HANDLE_EINTR(ioctl(ion_fd, ION_IOC_IMPORT, &fd_data));
err = HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_IMPORT, &fd_data));
assert(err == 0);

this->handle = fd_data.handle;
Expand Down Expand Up @@ -136,7 +139,7 @@ int VisionBuf::sync(int dir) {
ION_IOC_INV_CACHES : ION_IOC_CLEAN_CACHES;

custom_data.arg = (unsigned long)&flush_data;
return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data));
return HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_CUSTOM, &custom_data));
}

int VisionBuf::free() {
Expand All @@ -154,5 +157,5 @@ int VisionBuf::free() {
if (err != 0) return err;

struct ion_handle_data handle_data = {.handle = this->handle};
return HANDLE_EINTR(ioctl(ion_fd, ION_IOC_FREE, &handle_data));
return HANDLE_EINTR(ioctl(ion_fd(), ION_IOC_FREE, &handle_data));
}

0 comments on commit 94fb711

Please sign in to comment.