| /* |
| * Copyright 2017, Data61 |
| * Commonwealth Scientific and Industrial Research Organisation (CSIRO) |
| * ABN 41 687 119 230. |
| * |
| * This software may be distributed and modified according to the terms of |
| * the GNU General Public License version 2. Note that NO WARRANTY is provided. |
| * See "LICENSE_GPLv2.txt" for details. |
| * |
| * @TAG(DATA61_GPL) |
| */ |
| |
| #ifndef _ETHDRIVER_ZYNQ7000_IO_H_ |
| #define _ETHDRIVER_ZYNQ7000_IO_H_ |
| |
| #define __arch_getl(addr) *((volatile uint32_t*)(addr)) |
| #define __arch_getw(addr) *((volatile uint16_t*)(addr)) |
| #define __arch_getb(addr) *((volatile uint8_t*)(addr)) |
| |
| #define __arch_putl(val, addr) *((volatile uint32_t*)(addr)) = val |
| #define __arch_putw(val, addr) *((volatile uint16_t*)(addr)) = val |
| #define __arch_putb(val, addr) *((volatile uint8_t*)(addr)) = val |
| |
| |
| //#define __raw_writel(...) writel(__VA_ARGS__) |
| //#define __raw_readl(...) readl(__VA_ARGS__) |
| |
| |
| |
| |
| #define __raw_writeb(v,a) __arch_putb(v,a) |
| #define __raw_writew(v,a) __arch_putw(v,a) |
| #define __raw_writel(v,a) __arch_putl(v,a) |
| |
| #define __raw_readb(a) __arch_getb(a) |
| #define __raw_readw(a) __arch_getw(a) |
| #define __raw_readl(a) __arch_getl(a) |
| |
| /* |
| * TODO: The kernel offers some more advanced versions of barriers, it might |
| * have some advantages to use them instead of the simple one here. |
| */ |
| #define dmb() asm volatile("dmb" ::: "memory") |
| #define dsb() asm volatile("dsb" ::: "memory") |
| #define isb() asm volatile("isb" ::: "memory") |
| #define __iormb() dmb() |
| #define __iowmb() dmb() |
| |
| #define writeb(v,c) ({ uint8_t __v = v; __iowmb(); __arch_putb(__v,c); __v; }) |
| #define writew(v,c) ({ uint16_t __v = v; __iowmb(); __arch_putw(__v,c); __v; }) |
| #define writel(v,c) ({ uint32_t __v = v; __iowmb(); __arch_putl(__v,c); __v; }) |
| |
| #define readb(c) ({ uint8_t __v = __arch_getb(c); __iormb(); __v; }) |
| #define readw(c) ({ uint16_t __v = __arch_getw(c); __iormb(); __v; }) |
| #define readl(c) ({ uint32_t __v = __arch_getl(c); __iormb(); __v; }) |
| |
| |
| |
| #define __cpu_to_le64(x) ((__force __le64)(__u64)(x)) |
| #define __le64_to_cpu(x) ((__force __u64)(__le64)(x)) |
| #define __cpu_to_le32(x) ((__force __le32)(__u32)(x)) |
| #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) |
| #define __cpu_to_le16(x) ((__force __le16)(__u16)(x)) |
| #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) |
| #define __cpu_to_be64(x) ((__force __be64)__swab64((x))) |
| #define __be64_to_cpu(x) __swab64((__force __u64)(__be64)(x)) |
| #define __cpu_to_be32(x) ((__force __be32)__swab32((x))) |
| #define __be32_to_cpu(x) __swab32((__force __u32)(__be32)(x)) |
| #define __cpu_to_be16(x) ((__force __be16)__swab16((x))) |
| #define __be16_to_cpu(x) __swab16((__force __u16)(__be16)(x)) |
| |
| #define cpu_to_le64 __cpu_to_le64 |
| #define le64_to_cpu __le64_to_cpu |
| #define cpu_to_le32 __cpu_to_le32 |
| #define le32_to_cpu __le32_to_cpu |
| #define cpu_to_le16 __cpu_to_le16 |
| #define le16_to_cpu __le16_to_cpu |
| #define cpu_to_be64 __cpu_to_be64 |
| #define be64_to_cpu __be64_to_cpu |
| #define cpu_to_be32 __cpu_to_be32 |
| #define be32_to_cpu __be32_to_cpu |
| #define cpu_to_be16 __cpu_to_be16 |
| #define be16_to_cpu __be16_to_cpu |
| #define cpu_to_le64p __cpu_to_le64p |
| #define le64_to_cpup __le64_to_cpup |
| #define cpu_to_le32p __cpu_to_le32p |
| #define le32_to_cpup __le32_to_cpup |
| #define cpu_to_le16p __cpu_to_le16p |
| #define le16_to_cpup __le16_to_cpup |
| #define cpu_to_be64p __cpu_to_be64p |
| #define be64_to_cpup __be64_to_cpup |
| #define cpu_to_be32p __cpu_to_be32p |
| #define be32_to_cpup __be32_to_cpup |
| #define cpu_to_be16p __cpu_to_be16p |
| #define be16_to_cpup __be16_to_cpup |
| #define cpu_to_le64s __cpu_to_le64s |
| #define le64_to_cpus __le64_to_cpus |
| #define cpu_to_le32s __cpu_to_le32s |
| #define le32_to_cpus __le32_to_cpus |
| #define cpu_to_le16s __cpu_to_le16s |
| #define le16_to_cpus __le16_to_cpus |
| #define cpu_to_be64s __cpu_to_be64s |
| #define be64_to_cpus __be64_to_cpus |
| #define cpu_to_be32s __cpu_to_be32s |
| #define be32_to_cpus __be32_to_cpus |
| #define cpu_to_be16s __cpu_to_be16s |
| #define be16_to_cpus __be16_to_cpus |
| |
| #define out_arch(type, endian, a, v) __raw_write##type(cpu_to_##endian(v), a) |
| #define in_arch(type, endian, a) endian##_to_cpu(__raw_read##type(a)) |
| |
| #define out_le32(a, v) out_arch(l, le32, a, v) |
| #define out_le16(a, v) out_arch(w, le16, a, v) |
| |
| #define in_le32(a) in_arch(l, le32, a) |
| #define in_le16(a) in_arch(w, le16, a) |
| |
| #define out_be32(a, v) out_arch(l, be32, a, v) |
| #define out_be16(a, v) out_arch(w, be16, a, v) |
| |
| #define in_be32(a) in_arch(l, be32, a) |
| #define in_be16(a) in_arch(w, be16, a) |
| |
| #define out_8(a, v) __raw_writeb(v, a) |
| #define in_8(a) __raw_readb(a) |
| |
| /* |
| * Clear and set bits in one shot. These macros can be used to clear and |
| * set multiple bits in a register using a single call. These macros can |
| * also be used to set a multiple-bit bit pattern using a mask, by |
| * specifying the mask in the 'clear' parameter and the new bit pattern |
| * in the 'set' parameter. |
| */ |
| |
| #define clrbits(type, addr, clear) \ |
| out_##type((addr), in_##type(addr) & ~(clear)) |
| |
| #define setbits(type, addr, set) \ |
| out_##type((addr), in_##type(addr) | (set)) |
| |
| #define clrsetbits(type, addr, clear, set) \ |
| out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) |
| |
| #define clrbits_be32(addr, clear) clrbits(be32, addr, clear) |
| #define setbits_be32(addr, set) setbits(be32, addr, set) |
| #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) |
| |
| #define clrbits_le32(addr, clear) clrbits(le32, addr, clear) |
| #define setbits_le32(addr, set) setbits(le32, addr, set) |
| #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) |
| |
| #define clrbits_be16(addr, clear) clrbits(be16, addr, clear) |
| #define setbits_be16(addr, set) setbits(be16, addr, set) |
| #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) |
| |
| #define clrbits_le16(addr, clear) clrbits(le16, addr, clear) |
| #define setbits_le16(addr, set) setbits(le16, addr, set) |
| #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) |
| |
| #define clrbits_8(addr, clear) clrbits(8, addr, clear) |
| #define setbits_8(addr, set) setbits(8, addr, set) |
| #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) |
| |
| #endif /* _ETHDRIVER_ZYNQ7000_IO_H_ */ |