Switchtec Userspace  PROJECT_NUMBER = PROJECT_NUMBER=PROJECT_NUMBER = 2.2
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 
33  uint32_t gas_offset;
34  uint32_t len;
35  uint8_t data[MRPC_MAX_DATA_LEN - 2 * sizeof(uint32_t)];
36 };
37 
38 struct gas_mrpc_read {
39  uint32_t gas_offset;
40  uint32_t len;
41 };
42 
43 void gas_mrpc_memcpy_to_gas(struct switchtec_dev *dev, void __gas *dest,
44  const void *src, size_t n);
45 void gas_mrpc_memcpy_from_gas(struct switchtec_dev *dev, void *dest,
46  const void __gas *src, size_t n);
47 ssize_t gas_mrpc_write_from_gas(struct switchtec_dev *dev, int fd,
48  const void __gas *src, size_t n);
49 
50 #define create_mrpc_gas_read(type, suffix) \
51  static inline type gas_mrpc_read ## suffix(struct switchtec_dev *dev, \
52  type __gas *addr) \
53  { \
54  type ret; \
55  gas_mrpc_memcpy_from_gas(dev, &ret, addr, sizeof(ret)); \
56  return ret; \
57  }
58 
59 #define create_mrpc_gas_write(type, suffix) \
60  static inline void gas_mrpc_write ## suffix(struct switchtec_dev *dev, \
61  type val, type __gas *addr) \
62  { \
63  gas_mrpc_memcpy_to_gas(dev, addr, &val, sizeof(val)); \
64  }
65 
66 create_mrpc_gas_read(uint8_t, 8);
67 create_mrpc_gas_read(uint16_t, 16);
68 create_mrpc_gas_read(uint32_t, 32);
69 create_mrpc_gas_read(uint64_t, 64);
70 
71 create_mrpc_gas_write(uint8_t, 8);
72 create_mrpc_gas_write(uint16_t, 16);
73 create_mrpc_gas_write(uint32_t, 32);
74 create_mrpc_gas_write(uint64_t, 64);
75 
76 #undef create_mrpc_gas_read
77 #undef create_mrpc_gas_write
78 
79 #endif
void 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:90
Main Switchtec header.
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:120
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:57