Switchtec Userspace PROJECT_NUMBER = 4.2
Loading...
Searching...
No Matches
mmap_gas.h
Go to the documentation of this file.
1/*
2 * Microsemi Switchtec(tm) PCIe Management Library
3 * Copyright (c) 2017, 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
30
31#ifndef LIBSWITCHTEC_MMAP_GAS_H
32#define LIBSWITCHTEC_MMAP_GAS_H
33
34#include <unistd.h>
35#include <stdint.h>
36#include <string.h>
37
38#ifdef __CHECKER__
39#define __force __attribute__((force))
40#else
41#define __force
42#endif
43
44#include "../switchtec_priv.h"
45
46static void mmap_memcpy_to_gas(struct switchtec_dev *dev, void __gas *dest,
47 const void *src, size_t n)
48{
49 memcpy((void __force *)dest, src, n);
50}
51
52static void mmap_memcpy_from_gas(struct switchtec_dev *dev, void *dest,
53 const void __gas *src, size_t n)
54{
55 memcpy(dest, (void __force *)src, n);
56}
57
58static ssize_t mmap_write_from_gas(struct switchtec_dev *dev, int fd,
59 const void __gas *src, size_t n)
60{
61 return write(fd, (void __force *)src, n);
62}
63
64#define create_gas_read(type, suffix) \
65 static type mmap_gas_read ## suffix(struct switchtec_dev *dev, \
66 type __gas *addr) \
67 { \
68 type *safe_addr = (type __force *)addr; \
69 asm volatile("": : :"memory"); \
70 return *safe_addr; \
71 }
72
73#define create_gas_write(type, suffix) \
74 static void mmap_gas_write ## suffix(struct switchtec_dev *dev, \
75 type val, type __gas *addr) \
76 { \
77 type *safe_addr = (type __force *)addr; \
78 asm volatile("": : :"memory"); \
79 *safe_addr = val; \
80 }
81
82create_gas_read(uint8_t, 8);
83create_gas_read(uint16_t, 16);
84create_gas_read(uint32_t, 32);
85create_gas_read(uint64_t, 64);
86
87create_gas_write(uint8_t, 8);
88create_gas_write(uint16_t, 16);
89create_gas_write(uint32_t, 32);
90create_gas_write(uint64_t, 64);
91
92#undef __force
93
94#endif