Switchtec Userspace
PROJECT_NUMBER = 4.2
Toggle main menu visibility
Loading...
Searching...
No Matches
inc
switchtec
gas_mrpc.h
1
/*
2
* Microsemi Switchtec(tm) PCIe Management Library
3
* Copyright (c) 2019, Microsemi Corporation
4
*
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
11
*
12
* The above copyright notice and this permission notice shall be included
13
* in all copies or substantial portions of the Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
* OTHER DEALINGS IN THE SOFTWARE.
22
*
23
*/
24
25
#ifndef LIBSWITCHTEC_GAS_MRPC_H
26
#define LIBSWITCHTEC_GAS_MRPC_H
27
28
#include <switchtec/mrpc.h>
29
#include <
switchtec/switchtec.h
>
30
#include <stdint.h>
31
#include <switchtec/endian.h>
32
33
struct
gas_mrpc_write
{
34
uint32_t gas_offset;
35
uint32_t len;
36
uint8_t data[MRPC_MAX_DATA_LEN - 2 *
sizeof
(uint32_t)];
37
};
38
39
struct
gas_mrpc_read
{
40
uint32_t gas_offset;
41
uint32_t len;
42
};
43
44
void
gas_mrpc_memcpy_to_gas
(
struct
switchtec_dev *dev,
void
__gas *dest,
45
const
void
*src,
size_t
n);
46
int
gas_mrpc_memcpy_from_gas
(
struct
switchtec_dev *dev,
void
*dest,
47
const
void
__gas *src,
size_t
n);
48
ssize_t
gas_mrpc_write_from_gas
(
struct
switchtec_dev *dev,
int
fd,
49
const
void
__gas *src,
size_t
n);
50
51
// noop conversion functions to make macros below work
52
static
inline
uint8_t le8toh(uint8_t x) {
return
x; }
53
static
inline
uint8_t htole8(uint8_t x) {
return
x; }
54
55
#define create_mrpc_gas_read(type, suffix) \
56
static inline int gas_mrpc_read ## suffix(struct switchtec_dev *dev, \
57
type __gas *addr, \
58
type *data) \
59
{ \
60
int ret; \
61
ret = gas_mrpc_memcpy_from_gas(dev, data, addr, \
62
sizeof(type)); \
63
*data = le##suffix##toh(*data); \
64
return ret; \
65
}
66
67
#define create_mrpc_gas_write(type, suffix) \
68
static inline void gas_mrpc_write ## suffix(struct switchtec_dev *dev, \
69
type val, type __gas *addr) \
70
{ \
71
val = htole##suffix (val); \
72
gas_mrpc_memcpy_to_gas(dev, addr, &val, sizeof(val)); \
73
}
74
75
create_mrpc_gas_read(uint8_t, 8);
76
create_mrpc_gas_read(uint16_t, 16);
77
create_mrpc_gas_read(uint32_t, 32);
78
create_mrpc_gas_read(uint64_t, 64);
79
80
create_mrpc_gas_write(uint8_t, 8);
81
create_mrpc_gas_write(uint16_t, 16);
82
create_mrpc_gas_write(uint32_t, 32);
83
create_mrpc_gas_write(uint64_t, 64);
84
85
#undef create_mrpc_gas_read
86
#undef create_mrpc_gas_write
87
88
#endif
gas_mrpc_memcpy_to_gas
void gas_mrpc_memcpy_to_gas(struct switchtec_dev *dev, void __gas *dest, const void *src, size_t n)
Copy data to the GAS using MRPC commands.
Definition
gas_mrpc.c:59
gas_mrpc_memcpy_from_gas
int gas_mrpc_memcpy_from_gas(struct switchtec_dev *dev, void *dest, const void __gas *src, size_t n)
Copy data from the GAS using MRPC commands.
Definition
gas_mrpc.c:94
gas_mrpc_write_from_gas
ssize_t gas_mrpc_write_from_gas(struct switchtec_dev *dev, int fd, const void __gas *src, size_t n)
Call write() with data from the GAS using an MRPC command.
Definition
gas_mrpc.c:131
gas_mrpc_read
Definition
gas_mrpc.h:39
gas_mrpc_write
Definition
gas_mrpc.h:33
switchtec.h
Main Switchtec header.
Generated by
1.17.0