Lines Matching refs:rmem

20 static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem);
53 static int rmtfs_mem_open_rfsa(struct rmtfs_mem *rmem, int client_id) in rmtfs_mem_open_rfsa() argument
71 rmem->fd = fd; in rmtfs_mem_open_rfsa()
95 ret = parse_hex_sysattr(dev, "phys_addr", &rmem->address); in rmtfs_mem_open_rfsa()
102 ret = parse_hex_sysattr(dev, "size", &rmem->size); in rmtfs_mem_open_rfsa()
123 static int rmtfs_mem_open_uio(struct rmtfs_mem *rmem, int client_id) in rmtfs_mem_open_uio() argument
141 rmem->fd = fd; in rmtfs_mem_open_uio()
165 ret = parse_hex_sysattr(dev, "maps/map0/addr", &rmem->address); in rmtfs_mem_open_uio()
172 ret = parse_hex_sysattr(dev, "maps/map0/size", &rmem->size); in rmtfs_mem_open_uio()
179 rmem->base = mmap(0, rmem->size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); in rmtfs_mem_open_uio()
180 if (rmem->base == MAP_FAILED) { in rmtfs_mem_open_uio()
204 static int rmtfs_mem_open_rfsa(struct rmtfs_mem *rmem, int client_id) in rmtfs_mem_open_rfsa() argument
215 rmem->fd = open(path, O_RDWR); in rmtfs_mem_open_rfsa()
216 if (rmem->fd < 0) { in rmtfs_mem_open_rfsa()
230 rmem->address = strtoull(val, &endptr, 16); in rmtfs_mem_open_rfsa()
231 if ((rmem->address == ULLONG_MAX && errno == ERANGE) || endptr == val) { in rmtfs_mem_open_rfsa()
245 rmem->size = strtoull(val, &endptr, 16); in rmtfs_mem_open_rfsa()
246 if ((rmem->size == ULLONG_MAX && errno == ERANGE) || endptr == val) { in rmtfs_mem_open_rfsa()
259 static int rmtfs_mem_open_uio(struct rmtfs_mem *rmem __unused, int client_id __unused) in rmtfs_mem_open_uio()
269 struct rmtfs_mem *rmem; in rmtfs_mem_open() local
274 rmem = malloc(sizeof(*rmem)); in rmtfs_mem_open()
275 if (!rmem) in rmtfs_mem_open()
278 memset(rmem, 0, sizeof(*rmem)); in rmtfs_mem_open()
280 ret = rmtfs_mem_open_rfsa(rmem, 1); in rmtfs_mem_open()
285 ret = rmtfs_mem_open_uio(rmem, 1); in rmtfs_mem_open()
291 ret = rmtfs_mem_enumerate(rmem); in rmtfs_mem_open()
301 base = mmap(0, rmem->size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, rmem->address); in rmtfs_mem_open()
307 rmem->base = base; in rmtfs_mem_open()
308 rmem->fd = fd; in rmtfs_mem_open()
312 return rmem; in rmtfs_mem_open()
317 free(rmem); in rmtfs_mem_open()
321 int64_t rmtfs_mem_alloc(struct rmtfs_mem *rmem, size_t alloc_size) in rmtfs_mem_alloc() argument
323 if (alloc_size > rmem->size) { in rmtfs_mem_alloc()
326 alloc_size, rmem->size); in rmtfs_mem_alloc()
330 return rmem->address; in rmtfs_mem_alloc()
333 void rmtfs_mem_free(struct rmtfs_mem *rmem __unused) in rmtfs_mem_free()
337 static void *rmtfs_mem_ptr(struct rmtfs_mem *rmem, unsigned long phys_address, ssize_t len) in rmtfs_mem_ptr() argument
348 if (start < rmem->address || end > rmem->address + rmem->size) in rmtfs_mem_ptr()
351 return (char*)rmem->base + phys_address - rmem->address; in rmtfs_mem_ptr()
354 ssize_t rmtfs_mem_read(struct rmtfs_mem *rmem, unsigned long phys_address, void *buf, ssize_t len) in rmtfs_mem_read() argument
359 if (rmem->base) { in rmtfs_mem_read()
360 ptr = rmtfs_mem_ptr(rmem, phys_address, len); in rmtfs_mem_read()
366 offset = phys_address - rmem->address; in rmtfs_mem_read()
367 len = pread(rmem->fd, buf, len, offset); in rmtfs_mem_read()
373 ssize_t rmtfs_mem_write(struct rmtfs_mem *rmem, unsigned long phys_address, const void *buf, ssize_… in rmtfs_mem_write() argument
378 if (rmem->base) { in rmtfs_mem_write()
379 ptr = rmtfs_mem_ptr(rmem, phys_address, len); in rmtfs_mem_write()
385 offset = phys_address - rmem->address; in rmtfs_mem_write()
386 len = pwrite(rmem->fd, buf, len, offset); in rmtfs_mem_write()
392 void rmtfs_mem_close(struct rmtfs_mem *rmem) in rmtfs_mem_close() argument
394 if (rmem->base) in rmtfs_mem_close()
395 munmap(rmem->base, rmem->size); in rmtfs_mem_close()
397 close(rmem->fd); in rmtfs_mem_close()
399 free(rmem); in rmtfs_mem_close()
402 static int rmtfs_mem_enumerate(struct rmtfs_mem *rmem) in rmtfs_mem_enumerate() argument
448 rmem->address = be32toh(reg.dw[0]); in rmtfs_mem_enumerate()
449 rmem->size = be32toh(reg.dw[1]); in rmtfs_mem_enumerate()
451 rmem->address = be64toh(reg.qw[0]); in rmtfs_mem_enumerate()
452 rmem->size = be64toh(reg.qw[1]); in rmtfs_mem_enumerate()