forked from Xilinx/AVED
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathami_peek_poke_access.c
More file actions
86 lines (69 loc) · 2.31 KB
/
ami_peek_poke_access.c
File metadata and controls
86 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: GPL-2.0-only
/*
* ami_peek_poke_access.c - This file contains functions to read/write HPU registers
*
*/
/*****************************************************************************/
/* Includes */
/*****************************************************************************/
/* Standard includes */
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
/* Public API includes */
#include "ami_peek_poke_access.h"
/* Private API includes */
#include "ami_ioctl.h"
#include "ami_internal.h"
#include "ami_device_internal.h"
/*****************************************************************************/
/* Public API function definitions */
/*****************************************************************************/
int ami_peek(ami_device *dev, uint32_t offset, uint32_t num, uint32_t *val)
{
int ret = AMI_STATUS_ERROR;
struct ami_ioc_peek_poke_payload data = { 0 };
if (!dev || !val)
return AMI_API_ERROR(AMI_ERROR_EINVAL);
if (ami_open_cdev(dev) != AMI_STATUS_OK)
return AMI_STATUS_ERROR; /* last error is set by ami_open_cdev */
data.addr = (unsigned long)val;
data.len = num;
data.offset = offset;
if (ioctl(dev->cdev, AMI_IOC_PEEK, &data) == AMI_LINUX_STATUS_ERROR) {
ret = AMI_API_ERROR_M(
AMI_ERROR_EIO,
"errno %d (%s)",
errno,
strerror(errno)
);
} else {
ret = AMI_STATUS_OK;
}
return ret;
}
int ami_poke(ami_device *dev, uint32_t offset, uint32_t num, uint32_t *val)
{
int ret = AMI_STATUS_ERROR;
struct ami_ioc_peek_poke_payload data = { 0 };
if (!dev || !val)
return AMI_API_ERROR(AMI_ERROR_EINVAL);
if (ami_open_cdev(dev) != AMI_STATUS_OK)
return AMI_STATUS_ERROR; /* last error is set by ami_open_cdev */
data.addr = (unsigned long)val;
data.len = num;
data.offset = offset;
if (ioctl(dev->cdev, AMI_IOC_POKE, &data) == AMI_LINUX_STATUS_ERROR) {
ret = AMI_API_ERROR_M(
AMI_ERROR_EIO,
"errno %d (%s)",
errno,
strerror(errno)
);
} else {
ret = AMI_STATUS_OK;
}
return ret;
}