Skip to content

Commit 5327c78

Browse files
dhobsongPhil Edworthy
authored andcommitted
Use uio device_index instead of resid to access memory allocation map
The uio.device_index is unique for each UIO device, whereas the resid is defined by the order in which the UIO devices are opened via uio_open_named or uio_open_blocks and may differ from one process to another. With the addition of this patch the resid argument to uio_malloc() and uio_free() has become unnecessary and so has been removed.
1 parent cdda58e commit 5327c78

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/libuiomux/uio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int uio_mem_free(int fd, int res, int offset, int count)
482482
return ret;
483483
}
484484

485-
void *uio_malloc(struct uio *uio, int resid, size_t size, int align, int shared)
485+
void *uio_malloc(struct uio *uio, size_t size, int align, int shared)
486486
{
487487
unsigned char * mem_base;
488488
int pagesize, pages_req, pages_max;
@@ -500,18 +500,18 @@ void *uio_malloc(struct uio *uio, int resid, size_t size, int align, int shared)
500500
pages_max = (uio->mem.size + pagesize - 1) / pagesize;
501501
pages_req = (size + pagesize - 1) / pagesize;
502502

503-
if ((base = uio_mem_find(uio->dev.fd, resid,
503+
if ((base = uio_mem_find(uio->dev.fd, uio->device_index,
504504
pages_max, pages_req, shared)) == -1)
505505
return NULL;
506-
uio_mem_alloc(uio->dev.fd, resid, base, pages_req, shared);
506+
uio_mem_alloc(uio->dev.fd, uio->device_index, base, pages_req, shared);
507507

508508
mem_base = (void *)
509509
((unsigned long)uio->mem.iomem + (base * pagesize));
510510

511511
return mem_base;
512512
}
513513

514-
void uio_free(struct uio *uio, int resid, void *address, size_t size)
514+
void uio_free(struct uio *uio, void *address, size_t size)
515515
{
516516
int pagesize, base, pages_req;
517517

@@ -520,7 +520,7 @@ void uio_free(struct uio *uio, int resid, void *address, size_t size)
520520
base = (int)(((unsigned long)address -
521521
(unsigned long)uio->mem.iomem) / pagesize);
522522
pages_req = (size + pagesize - 1) / pagesize;
523-
uio_mem_free(uio->dev.fd, resid, base, pages_req);
523+
uio_mem_free(uio->dev.fd, uio->device_index, base, pages_req);
524524
}
525525

526526
static void print_usage(int pid, long base, long top)

src/libuiomux/uio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ int
6363
uio_read_nonblocking(struct uio *uio);
6464

6565
void *
66-
uio_malloc (struct uio * uio, int resid, size_t size, int align, int shared);
66+
uio_malloc (struct uio * uio, size_t size, int align, int shared);
6767

6868
void
69-
uio_free (struct uio * uio, int resid, void * address, size_t size);
69+
uio_free (struct uio * uio, void * address, size_t size);
7070

7171
void
7272
uio_meminfo (struct uio * uio);

src/libuiomux/uiomux.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void *uiomux_malloc(struct uiomux *uiomux, uiomux_resource_t blockmask,
407407
if (!mem)
408408
return NULL;
409409

410-
ret = uio_malloc(uio, i, size, align, 0);
410+
ret = uio_malloc(uio, size, align, 0);
411411

412412
if (ret) {
413413
mem->virt = ret;
@@ -446,7 +446,7 @@ void *uiomux_malloc_shared(struct uiomux *uiomux, uiomux_resource_t blockmask,
446446
fprintf(stderr, "%s: Allocating %d bytes shm for block %d\n",
447447
__func__, size, i);
448448
#endif
449-
ret = uio_malloc(uio, i, size, align, 1);
449+
ret = uio_malloc(uio, size, align, 1);
450450
}
451451

452452
return ret;
@@ -471,7 +471,7 @@ uiomux_free(struct uiomux *uiomux, uiomux_resource_t blockmask,
471471
fprintf(stderr, "%s: Freeing memory for block %d\n",
472472
__func__, i);
473473
#endif
474-
uio_free(uio, i, address, size);
474+
uio_free(uio, address, size);
475475

476476
pthread_mutex_lock(&mutex);
477477
mem = find_mem_block(&g_mem_regions, address);

0 commit comments

Comments
 (0)