mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-08-18 11:52:08 +08:00
mmio: consolidate map and unmap error codes to open and close
This commit is contained in:
+5
-7
@@ -164,13 +164,11 @@ The periphery MMIO functions return 0 on success or one of the negative error co
|
||||
|
||||
The libc errno of the failure in an underlying libc library call can be obtained with the `mmio_errno()` helper function. A human readable error message can be obtained with the `mmio_errmsg()` helper function.
|
||||
|
||||
| Error Code | Description |
|
||||
|-----------------------|-------------------------------|
|
||||
| `MMIO_ERROR_ARG` | Invalid arguments |
|
||||
| `MMIO_ERROR_OPEN` | Opening /dev/mem |
|
||||
| `MMIO_ERROR_MAP` | Mapping memory |
|
||||
| `MMIO_ERROR_CLOSE` | Closing /dev/mem |
|
||||
| `MMIO_ERROR_UNMAP` | Unmapping memory |
|
||||
| Error Code | Description |
|
||||
|-----------------------|-----------------------|
|
||||
| `MMIO_ERROR_ARG` | Invalid arguments |
|
||||
| `MMIO_ERROR_OPEN` | Opening MMIO |
|
||||
| `MMIO_ERROR_CLOSE` | Closing MMIO |
|
||||
|
||||
### EXAMPLE
|
||||
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ int mmio_open(mmio_t *mmio, uintptr_t base, size_t size) {
|
||||
if ((mmio->ptr = mmap(0, mmio->aligned_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mmio->aligned_base)) == MAP_FAILED) {
|
||||
int errsv = errno;
|
||||
close(fd);
|
||||
return _mmio_error(mmio, MMIO_ERROR_MAP, errsv, "Mapping memory");
|
||||
return _mmio_error(mmio, MMIO_ERROR_OPEN, errsv, "Mapping memory");
|
||||
}
|
||||
|
||||
/* Close memory */
|
||||
@@ -171,7 +171,7 @@ int mmio_close(mmio_t *mmio) {
|
||||
|
||||
/* Unmap memory */
|
||||
if (munmap(mmio->ptr, mmio->aligned_size) < 0)
|
||||
return _mmio_error(mmio, MMIO_ERROR_UNMAP, errno, "Unmapping memory");
|
||||
return _mmio_error(mmio, MMIO_ERROR_CLOSE, errno, "Unmapping memory");
|
||||
|
||||
mmio->ptr = 0;
|
||||
|
||||
|
||||
+2
-4
@@ -17,10 +17,8 @@ extern "C" {
|
||||
|
||||
enum mmio_error_code {
|
||||
MMIO_ERROR_ARG = -1, /* Invalid arguments */
|
||||
MMIO_ERROR_OPEN = -2, /* Opening /dev/mem */
|
||||
MMIO_ERROR_MAP = -3, /* Mapping memory */
|
||||
MMIO_ERROR_CLOSE = -4, /* Closing /dev/mem */
|
||||
MMIO_ERROR_UNMAP = -5, /* Unmapping memory */
|
||||
MMIO_ERROR_OPEN = -2, /* Opening MMIO */
|
||||
MMIO_ERROR_CLOSE = -3, /* Closing MMIO */
|
||||
};
|
||||
|
||||
typedef struct mmio_handle mmio_t;
|
||||
|
||||
Reference in New Issue
Block a user