]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/logic_pio.h
5c56b9e1355442ae43d828afa0d87f9e44f5dedb
[mirror_ubuntu-bionic-kernel.git] / include / linux / logic_pio.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2017 Hisilicon Limited, All Rights Reserved.
4 * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
5 * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
6 *
7 */
8
9 #ifndef __LINUX_LOGIC_PIO_H
10 #define __LINUX_LOGIC_PIO_H
11
12 #ifdef __KERNEL__
13
14 #include <linux/fwnode.h>
15
16 #define PIO_INDIRECT 0x01UL /* indirect IO flag */
17 #define PIO_CPU_MMIO 0x00UL /* memory mapped io flag */
18
19 struct logic_pio_hwaddr {
20 struct list_head list;
21 struct fwnode_handle *fwnode;
22 resource_size_t hw_start;
23 resource_size_t io_start;
24 resource_size_t size; /* range size populated */
25 unsigned long flags;
26
27 void *hostdata;
28 const struct logic_pio_host_ops *ops;
29 };
30
31 struct logic_pio_host_ops {
32 u32 (*in)(void *hostdata, unsigned long addr, size_t dwidth);
33 void (*out)(void *hostdata, unsigned long addr, u32 val,
34 size_t dwidth);
35 u32 (*ins)(void *hostdata, unsigned long addr, void *buffer,
36 size_t dwidth, unsigned int count);
37 void (*outs)(void *hostdata, unsigned long addr, const void *buffer,
38 size_t dwidth, unsigned int count);
39 };
40
41 #ifdef CONFIG_INDIRECT_PIO
42 u8 logic_inb(unsigned long addr);
43 void logic_outb(u8 value, unsigned long addr);
44 void logic_outw(u16 value, unsigned long addr);
45 void logic_outl(u32 value, unsigned long addr);
46 u16 logic_inw(unsigned long addr);
47 u32 logic_inl(unsigned long addr);
48 void logic_outb(u8 value, unsigned long addr);
49 void logic_outw(u16 value, unsigned long addr);
50 void logic_outl(u32 value, unsigned long addr);
51 void logic_insb(unsigned long addr, void *buffer, unsigned int count);
52 void logic_insl(unsigned long addr, void *buffer, unsigned int count);
53 void logic_insw(unsigned long addr, void *buffer, unsigned int count);
54 void logic_outsb(unsigned long addr, const void *buffer, unsigned int count);
55 void logic_outsw(unsigned long addr, const void *buffer, unsigned int count);
56 void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);
57
58 #ifndef inb
59 #define inb logic_inb
60 #endif
61
62 #ifndef inw
63 #define inw logic_inw
64 #endif
65
66 #ifndef inl
67 #define inl logic_inl
68 #endif
69
70 #ifndef outb
71 #define outb logic_outb
72 #endif
73
74 #ifndef outw
75 #define outw logic_outw
76 #endif
77
78 #ifndef outl
79 #define outl logic_outl
80 #endif
81
82 #ifndef insb
83 #define insb logic_insb
84 #endif
85
86 #ifndef insw
87 #define insw logic_insw
88 #endif
89
90 #ifndef insl
91 #define insl logic_insl
92 #endif
93
94 #ifndef outsb
95 #define outsb logic_outsb
96 #endif
97
98 #ifndef outsw
99 #define outsw logic_outsw
100 #endif
101
102 #ifndef outsl
103 #define outsl logic_outsl
104 #endif
105
106 /*
107 * Below we reserve 0x4000 bytes for Indirect IO as so far this library is only
108 * used by Hisilicon LPC Host. If needed in future we may reserve a wider IO
109 * area by redefining the macro below.
110 */
111 #define PIO_INDIRECT_SIZE 0x4000
112 #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
113 #else
114 #define MMIO_UPPER_LIMIT IO_SPACE_LIMIT
115 #endif /* CONFIG_INDIRECT_PIO */
116
117
118 struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode);
119
120 unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
121 resource_size_t hw_addr, resource_size_t size);
122
123 int logic_pio_register_range(struct logic_pio_hwaddr *newrange);
124
125
126 extern resource_size_t logic_pio_to_hwaddr(unsigned long pio);
127
128 extern unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr);
129
130 #endif /* __KERNEL__ */
131 #endif /* __LINUX_LOGIC_PIO_H */