]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk/mmio.h
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * Memory-mapped I/O utility functions
41 #include "spdk/stdinc.h"
47 #include "spdk/barrier.h"
50 #define SPDK_MMIO_64BIT 1 /* Can do atomic 64-bit memory read/write (over PCIe) */
52 #define SPDK_MMIO_64BIT 0
56 spdk_mmio_read_1(const volatile uint8_t *addr
)
58 spdk_compiler_barrier();
63 spdk_mmio_write_1(volatile uint8_t *addr
, uint8_t val
)
65 spdk_compiler_barrier();
69 static inline uint16_t
70 spdk_mmio_read_2(const volatile uint16_t *addr
)
72 spdk_compiler_barrier();
77 spdk_mmio_write_2(volatile uint16_t *addr
, uint16_t val
)
79 spdk_compiler_barrier();
83 static inline uint32_t
84 spdk_mmio_read_4(const volatile uint32_t *addr
)
86 spdk_compiler_barrier();
91 spdk_mmio_write_4(volatile uint32_t *addr
, uint32_t val
)
93 spdk_compiler_barrier();
97 static inline uint64_t
98 spdk_mmio_read_8(volatile uint64_t *addr
)
101 volatile uint32_t *addr32
= (volatile uint32_t *)addr
;
103 spdk_compiler_barrier();
105 if (SPDK_MMIO_64BIT
) {
109 * Read lower 4 bytes before upper 4 bytes.
110 * This particular order is required by I/OAT.
111 * If the other order is required, use a pair of spdk_mmio_read_4() calls.
114 val
|= (uint64_t)addr32
[1] << 32;
121 spdk_mmio_write_8(volatile uint64_t *addr
, uint64_t val
)
123 volatile uint32_t *addr32
= (volatile uint32_t *)addr
;
125 spdk_compiler_barrier();
127 if (SPDK_MMIO_64BIT
) {
130 addr32
[0] = (uint32_t)val
;
131 addr32
[1] = (uint32_t)(val
>> 32);