162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _M68KNOMMU_IO_H
362306a36Sopenharmony_ci#define _M68KNOMMU_IO_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci * Convert a physical memory address into a IO memory address.
762306a36Sopenharmony_ci * For us this is trivially a type cast.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci#define iomem(a)	((void __iomem *) (a))
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci/*
1262306a36Sopenharmony_ci * The non-MMU m68k and ColdFire IO and memory mapped hardware access
1362306a36Sopenharmony_ci * functions have always worked in CPU native endian. We need to define
1462306a36Sopenharmony_ci * that behavior here first before we include asm-generic/io.h.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci#define __raw_readb(addr) \
1762306a36Sopenharmony_ci    ({ u8 __v = (*(__force volatile u8 *) (addr)); __v; })
1862306a36Sopenharmony_ci#define __raw_readw(addr) \
1962306a36Sopenharmony_ci    ({ u16 __v = (*(__force volatile u16 *) (addr)); __v; })
2062306a36Sopenharmony_ci#define __raw_readl(addr) \
2162306a36Sopenharmony_ci    ({ u32 __v = (*(__force volatile u32 *) (addr)); __v; })
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define __raw_writeb(b, addr) (void)((*(__force volatile u8 *) (addr)) = (b))
2462306a36Sopenharmony_ci#define __raw_writew(b, addr) (void)((*(__force volatile u16 *) (addr)) = (b))
2562306a36Sopenharmony_ci#define __raw_writel(b, addr) (void)((*(__force volatile u32 *) (addr)) = (b))
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#if defined(CONFIG_COLDFIRE)
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * For ColdFire platforms we may need to do some extra checks for what
3062306a36Sopenharmony_ci * type of address range we are accessing. Include the ColdFire platform
3162306a36Sopenharmony_ci * definitions so we can figure out if need to do something special.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci#include <asm/byteorder.h>
3462306a36Sopenharmony_ci#include <asm/coldfire.h>
3562306a36Sopenharmony_ci#include <asm/mcfsim.h>
3662306a36Sopenharmony_ci#endif /* CONFIG_COLDFIRE */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#if defined(IOMEMBASE)
3962306a36Sopenharmony_ci/*
4062306a36Sopenharmony_ci * The ColdFire SoC internal peripherals are mapped into virtual address
4162306a36Sopenharmony_ci * space using the ACR registers of the cache control unit. This means we
4262306a36Sopenharmony_ci * are using a 1:1 physical:virtual mapping for them. We can quickly
4362306a36Sopenharmony_ci * determine if we are accessing an internal peripheral device given the
4462306a36Sopenharmony_ci * physical or vitrual address using the same range check. This check logic
4562306a36Sopenharmony_ci * applies just the same of there is no MMU but something like a PCI bus
4662306a36Sopenharmony_ci * is present.
4762306a36Sopenharmony_ci */
4862306a36Sopenharmony_cistatic int __cf_internalio(unsigned long addr)
4962306a36Sopenharmony_ci{
5062306a36Sopenharmony_ci	return (addr >= IOMEMBASE) && (addr <= IOMEMBASE + IOMEMSIZE - 1);
5162306a36Sopenharmony_ci}
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cistatic int cf_internalio(const volatile void __iomem *addr)
5462306a36Sopenharmony_ci{
5562306a36Sopenharmony_ci	return __cf_internalio((unsigned long) addr);
5662306a36Sopenharmony_ci}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/*
5962306a36Sopenharmony_ci * We need to treat built-in peripherals and bus based address ranges
6062306a36Sopenharmony_ci * differently. Local built-in peripherals (and the ColdFire SoC parts
6162306a36Sopenharmony_ci * have quite a lot of them) are always native endian - which is big
6262306a36Sopenharmony_ci * endian on m68k/ColdFire. Bus based address ranges, like the PCI bus,
6362306a36Sopenharmony_ci * are accessed little endian - so we need to byte swap those.
6462306a36Sopenharmony_ci */
6562306a36Sopenharmony_ci#define readw readw
6662306a36Sopenharmony_cistatic inline u16 readw(const volatile void __iomem *addr)
6762306a36Sopenharmony_ci{
6862306a36Sopenharmony_ci	if (cf_internalio(addr))
6962306a36Sopenharmony_ci		return __raw_readw(addr);
7062306a36Sopenharmony_ci	return swab16(__raw_readw(addr));
7162306a36Sopenharmony_ci}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define readl readl
7462306a36Sopenharmony_cistatic inline u32 readl(const volatile void __iomem *addr)
7562306a36Sopenharmony_ci{
7662306a36Sopenharmony_ci	if (cf_internalio(addr))
7762306a36Sopenharmony_ci		return __raw_readl(addr);
7862306a36Sopenharmony_ci	return swab32(__raw_readl(addr));
7962306a36Sopenharmony_ci}
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define writew writew
8262306a36Sopenharmony_cistatic inline void writew(u16 value, volatile void __iomem *addr)
8362306a36Sopenharmony_ci{
8462306a36Sopenharmony_ci	if (cf_internalio(addr))
8562306a36Sopenharmony_ci		__raw_writew(value, addr);
8662306a36Sopenharmony_ci	else
8762306a36Sopenharmony_ci		__raw_writew(swab16(value), addr);
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define writel writel
9162306a36Sopenharmony_cistatic inline void writel(u32 value, volatile void __iomem *addr)
9262306a36Sopenharmony_ci{
9362306a36Sopenharmony_ci	if (cf_internalio(addr))
9462306a36Sopenharmony_ci		__raw_writel(value, addr);
9562306a36Sopenharmony_ci	else
9662306a36Sopenharmony_ci		__raw_writel(swab32(value), addr);
9762306a36Sopenharmony_ci}
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#else
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define readb __raw_readb
10262306a36Sopenharmony_ci#define readw __raw_readw
10362306a36Sopenharmony_ci#define readl __raw_readl
10462306a36Sopenharmony_ci#define writeb __raw_writeb
10562306a36Sopenharmony_ci#define writew __raw_writew
10662306a36Sopenharmony_ci#define writel __raw_writel
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#endif /* IOMEMBASE */
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci#if defined(CONFIG_PCI)
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * Support for PCI bus access uses the asm-generic access functions.
11362306a36Sopenharmony_ci * We need to supply the base address and masks for the normal memory
11462306a36Sopenharmony_ci * and IO address space mappings.
11562306a36Sopenharmony_ci */
11662306a36Sopenharmony_ci#define PCI_MEM_PA	0xf0000000		/* Host physical address */
11762306a36Sopenharmony_ci#define PCI_MEM_BA	0xf0000000		/* Bus physical address */
11862306a36Sopenharmony_ci#define PCI_MEM_SIZE	0x08000000		/* 128 MB */
11962306a36Sopenharmony_ci#define PCI_MEM_MASK	(PCI_MEM_SIZE - 1)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define PCI_IO_PA	0xf8000000		/* Host physical address */
12262306a36Sopenharmony_ci#define PCI_IO_BA	0x00000000		/* Bus physical address */
12362306a36Sopenharmony_ci#define PCI_IO_SIZE	0x00010000		/* 64k */
12462306a36Sopenharmony_ci#define PCI_IO_MASK	(PCI_IO_SIZE - 1)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#define HAVE_ARCH_PIO_SIZE
12762306a36Sopenharmony_ci#define PIO_OFFSET	0
12862306a36Sopenharmony_ci#define PIO_MASK	0xffff
12962306a36Sopenharmony_ci#define PIO_RESERVED	0x10000
13062306a36Sopenharmony_ci#define PCI_IOBASE	((void __iomem *) PCI_IO_PA)
13162306a36Sopenharmony_ci#define PCI_SPACE_LIMIT	PCI_IO_MASK
13262306a36Sopenharmony_ci#endif /* CONFIG_PCI */
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#include <asm/kmap.h>
13562306a36Sopenharmony_ci#include <asm/virtconvert.h>
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci#endif /* _M68KNOMMU_IO_H */
138