Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2017 HiSilicon Limited, All Rights Reserved.
0004  * Author: Gabriele Paoloni <gabriele.paoloni@huawei.com>
0005  * Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
0006  */
0007 
0008 #ifndef __LINUX_LOGIC_PIO_H
0009 #define __LINUX_LOGIC_PIO_H
0010 
0011 #include <linux/fwnode.h>
0012 
0013 enum {
0014     LOGIC_PIO_INDIRECT,     /* Indirect IO flag */
0015     LOGIC_PIO_CPU_MMIO,     /* Memory-mapped IO flag */
0016 };
0017 
0018 struct logic_pio_hwaddr {
0019     struct list_head list;
0020     struct fwnode_handle *fwnode;
0021     resource_size_t hw_start;
0022     resource_size_t io_start;
0023     resource_size_t size; /* range size populated */
0024     unsigned long flags;
0025 
0026     void *hostdata;
0027     const struct logic_pio_host_ops *ops;
0028 };
0029 
0030 struct logic_pio_host_ops {
0031     u32 (*in)(void *hostdata, unsigned long addr, size_t dwidth);
0032     void (*out)(void *hostdata, unsigned long addr, u32 val,
0033             size_t dwidth);
0034     u32 (*ins)(void *hostdata, unsigned long addr, void *buffer,
0035            size_t dwidth, unsigned int count);
0036     void (*outs)(void *hostdata, unsigned long addr, const void *buffer,
0037              size_t dwidth, unsigned int count);
0038 };
0039 
0040 #ifdef CONFIG_INDIRECT_PIO
0041 u8 logic_inb(unsigned long addr);
0042 void logic_outb(u8 value, unsigned long addr);
0043 void logic_outw(u16 value, unsigned long addr);
0044 void logic_outl(u32 value, unsigned long addr);
0045 u16 logic_inw(unsigned long addr);
0046 u32 logic_inl(unsigned long addr);
0047 void logic_outb(u8 value, unsigned long addr);
0048 void logic_outw(u16 value, unsigned long addr);
0049 void logic_outl(u32 value, unsigned long addr);
0050 void logic_insb(unsigned long addr, void *buffer, unsigned int count);
0051 void logic_insl(unsigned long addr, void *buffer, unsigned int count);
0052 void logic_insw(unsigned long addr, void *buffer, unsigned int count);
0053 void logic_outsb(unsigned long addr, const void *buffer, unsigned int count);
0054 void logic_outsw(unsigned long addr, const void *buffer, unsigned int count);
0055 void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);
0056 
0057 #ifndef inb
0058 #define inb logic_inb
0059 #endif
0060 
0061 #ifndef inw
0062 #define inw logic_inw
0063 #endif
0064 
0065 #ifndef inl
0066 #define inl logic_inl
0067 #endif
0068 
0069 #ifndef outb
0070 #define outb logic_outb
0071 #endif
0072 
0073 #ifndef outw
0074 #define outw logic_outw
0075 #endif
0076 
0077 #ifndef outl
0078 #define outl logic_outl
0079 #endif
0080 
0081 #ifndef insb
0082 #define insb logic_insb
0083 #endif
0084 
0085 #ifndef insw
0086 #define insw logic_insw
0087 #endif
0088 
0089 #ifndef insl
0090 #define insl logic_insl
0091 #endif
0092 
0093 #ifndef outsb
0094 #define outsb logic_outsb
0095 #endif
0096 
0097 #ifndef outsw
0098 #define outsw logic_outsw
0099 #endif
0100 
0101 #ifndef outsl
0102 #define outsl logic_outsl
0103 #endif
0104 
0105 /*
0106  * We reserve 0x4000 bytes for Indirect IO as so far this library is only
0107  * used by the HiSilicon LPC Host. If needed, we can reserve a wider IO
0108  * area by redefining the macro below.
0109  */
0110 #define PIO_INDIRECT_SIZE 0x4000
0111 #else
0112 #define PIO_INDIRECT_SIZE 0
0113 #endif /* CONFIG_INDIRECT_PIO */
0114 #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
0115 
0116 struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode);
0117 unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
0118             resource_size_t hw_addr, resource_size_t size);
0119 int logic_pio_register_range(struct logic_pio_hwaddr *newrange);
0120 void logic_pio_unregister_range(struct logic_pio_hwaddr *range);
0121 resource_size_t logic_pio_to_hwaddr(unsigned long pio);
0122 unsigned long logic_pio_trans_cpuaddr(resource_size_t hw_addr);
0123 
0124 #endif /* __LINUX_LOGIC_PIO_H */