1 /*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 /**
10 * @addtogroup OSAL
11 * @{
12 *
13 * @brief Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.
14 *
15 * The OSAL module OpenHarmony OS interface differences and provides unified OS interfaces externally,
16 * including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time,
17 * atomic, firmware, and I/O operation modules.
18 *
19 * @since 1.0
20 * @version 1.0
21 */
22
23 /**
24 * @file osal_io.h
25 *
26 * @brief Declares I/O interfaces.
27 *
28 * This file provides operations, such as reading data from and writing data into an I/O address space,
29 * remapping an I/O address space to its virtual address space, and unmapping an I/O virtual address
30 * associated with the physical address.
31 *
32 * @since 1.0
33 * @version 1.0
34 */
35
36 #ifndef OSAL_IO_H
37 #define OSAL_IO_H
38
39 #include "osal_io_adapter.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif /* __cplusplus */
44
45 /**
46 * @brief Writes one byte of data into an I/O address space.
47 *
48 * @param value Indicates the data to write.
49 * @param address Indicates the address to write.
50 *
51 * @since 1.0
52 * @version 1.0
53 */
54 #define OSAL_WRITEB(value, address) writeb(value, address)
55 /**
56 * @brief Writes a short integer into an I/O address space.
57 *
58 * @param value Indicates the data to write.
59 * @param address Indicates the address to write.
60 *
61 * @since 1.0
62 * @version 1.0
63 */
64 #define OSAL_WRITEW(value, address) writew(value, address)
65 /**
66 * @brief Writes an integer into an I/O address space.
67 *
68 * @param value Indicates the data to write.
69 * @param address Indicates the address to write.
70 *
71 * @since 1.0
72 * @version 1.0
73 */
74 #define OSAL_WRITEL(value, address) writel(value, address)
75
76 /**
77 * @brief Reads one byte of data from an I/O address space.
78 *
79 * @param address Indicates the address to read.
80 * @return Returns the byte.
81 *
82 * @since 1.0
83 * @version 1.0
84 */
85 #define OSAL_READB(address) readb(address)
86 /**
87 * @brief Reads a short integer from an I/O address space.
88 *
89 * @param address Indicates the address to read.
90 * @return Returns the short integer.
91 *
92 * @since 1.0
93 * @version 1.0
94 */
95 #define OSAL_READW(address) readw(address)
96 /**
97 * @brief Reads an integer from an I/O address space.
98 *
99 * @param address Indicates the address to read.
100 * @return Returns the integer.
101 *
102 * @since 1.0
103 * @version 1.0
104 */
105 #define OSAL_READL(address) readl(address)
106
107 /**
108 * @brief Remaps an I/O physical address to its virtual address.
109 *
110 * @param phys_addr Indicates the I/O physical address.
111 * @param size Indicates the size of the physical address to remap.
112 * @return Returns the virtual address.
113 *
114 * @since 1.0
115 * @version 1.0
116 */
OsalIoRemap(unsigned long phys_addr,unsigned long size)117 static inline void *OsalIoRemap(unsigned long phys_addr, unsigned long size)
118 {
119 return ioremap(phys_addr, size);
120 }
121
122 /**
123 * @brief Unmaps an I/O virtual address associated with the physical address.
124 *
125 * The virtual address is the one returned by calling {@link OsalIoRemap}.
126 *
127 * @param addr Indicates the pointer to the virtual address to unmap.
128 *
129 * @since 1.0
130 * @version 1.0
131 */
OsalIoUnmap(void * addr)132 static inline void OsalIoUnmap(void *addr)
133 {
134 iounmap(addr);
135 }
136
137 #ifdef __cplusplus
138 }
139 #endif /* __cplusplus */
140
141 #endif /* OSAL_IO_H */
142 /** @} */
143