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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Support for Digigram AlpX PCI-e boards
*
* Copyright (c) 2024 Digigram Digital (info@digigram.com)
*/
#include "alpx_axcmem.h"
#include <linux/module.h>
#include <linux/printk.h>
#include <asm/byteorder.h>
/* Items sizes in bytes*/
static const unsigned int AXCMEM_PAGE_SIZE = 32;
static const unsigned int AXCMEM_LINE_SIZE = 4;
/* AxCMem area offset */
static const uint32_t AXCMEM_AREA_OFFSET = 0x72000;
void* alpx_axcmem_getRegAddr(struct alpx_device* alp,
const struct alpx_axcmem_loc* loc)
{
dev_dbg(alp->dev," BAR:%p, loc{%d:%d:%d}\n",
alp->base,
loc->page, loc->line, loc->row);
return (uint8_t*)alp->base +
AXCMEM_AREA_OFFSET +
loc->page * AXCMEM_PAGE_SIZE +
loc->line * AXCMEM_LINE_SIZE +
loc->row;
}
void* alpx_axcmem_getPointedRegAddrByRefLoc(struct alpx_device* alp,
const struct alpx_axcmem_loc* ref_loc,
const struct alpx_axcmem_loc* loc)
{
void* const ref_reg_addr = alpx_axcmem_getRegAddr(alp, ref_loc);
dev_dbg(alp->dev, "BAR:%p, base:%p=>%d, loc{%d:%d:%d}\n",
alp->base, ref_reg_addr, alpx_axcmem_getRegU8Value(ref_reg_addr),
loc->page, loc->line, loc->row);
return (uint8_t*)alp->base + AXCMEM_AREA_OFFSET + alpx_axcmem_getRegU8Value(ref_reg_addr) * AXCMEM_PAGE_SIZE +
loc->page * AXCMEM_PAGE_SIZE +
loc->line * AXCMEM_LINE_SIZE +
loc->row;
}
int alpx_acxmem_getByteArrayByRefLoc(struct alpx_device* alp,
const struct alpx_axcmem_loc* ref_loc,
const struct alpx_axcmem_loc* loc,
unsigned char* dst,
unsigned int length)
{
unsigned int idx = 0;
const unsigned char* src = NULL;
if ((alp == NULL) ||
(ref_loc == NULL) ||
(loc == NULL) ||
(dst == NULL)) {
return -EINVAL;
}
if (length == 0)
return 0;
src = (unsigned char*) alpx_axcmem_getPointedRegAddrByRefLoc(alp, ref_loc, loc);
for (idx = 0 ; idx < length ; ++idx) {
dst[idx] = src[idx];
dev_dbg(alp->dev, " src[%d]: 0x%02x => dst[%d]: 0x%02x\n", idx, src[idx], idx, dst[idx]);
}
return 0;
}
uint32_t alpx_axcmem_getRegU8Value_ptr(void* addr)
{
return alpx_axcmem_getRegU8Value(addr);
}
void alpx_axcmem_setRegU8Value_ptr(void* addr, uint32_t value)
{
alpx_axcmem_setRegU8Value(addr, value);
}
uint32_t alpx_axcmem_getRegU16Value_ptr(void* addr)
{
return alpx_axcmem_getRegU16Value(addr);
}
void alpx_axcmem_setRegU16Value_ptr(void* addr, uint32_t value)
{
alpx_axcmem_setRegU16Value(addr, value);
}
uint32_t alpx_axcmem_getRegBEU16Value_ptr(void* addr)
{
return alpx_axcmem_getRegBEU16Value(addr);
}
void alpx_axcmem_setRegBEU16Value_ptr(void* addr, uint32_t value)
{
alpx_axcmem_setRegBEU16Value(addr, value);
}
uint32_t alpx_axcmem_getRegU32Value_ptr(void* addr)
{
return alpx_axcmem_getRegU32Value(addr);
}
void alpx_axcmem_setRegU32Value_ptr(void* addr, uint32_t value)
{
alpx_axcmem_setRegU32Value(addr, value);
}
uint32_t alpx_axcmem_getRegBEU32Value_ptr(void* addr)
{
return alpx_axcmem_getRegBEU32Value(addr);
}
void alpx_axcmem_setRegBEU32Value_ptr(void* addr, uint32_t value)
{
alpx_axcmem_setRegBEU32Value(addr, value);
}
|