io.h 7.4 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#ifndef _ASM_IA64_IO_H
#define _ASM_IA64_IO_H

/*
 * This file contains the definitions for the emulated IO instructions
 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
 * versions of the single-IO instructions (inb_p/inw_p/..).
 *
 * This file is not meant to be obfuscating: it's just complicated to
 * (a) handle it all in a way that makes gcc able to optimize it as
 * well as possible and (b) trying to avoid writing the same thing
 * over and over again with slight variations and possibly making a
 * mistake somewhere.
 *
 * Copyright (C) 1998-2003 Hewlett-Packard Co
 *	David Mosberger-Tang <davidm@hpl.hp.com>
 * Copyright (C) 1999 Asit Mallick <asit.k.mallick@intel.com>
 * Copyright (C) 1999 Don Dugger <don.dugger@intel.com>
 */

23
#include <asm/unaligned.h>
24
#include <asm/early_ioremap.h>
25

L
Linus Torvalds 已提交
26 27 28 29
/* We don't use IO slowdowns on the ia64, but.. */
#define __SLOW_DOWN_IO	do { } while (0)
#define SLOW_DOWN_IO	do { } while (0)

30
#define __IA64_UNCACHED_OFFSET	RGN_BASE(RGN_UNCACHED)
L
Linus Torvalds 已提交
31 32 33 34 35 36 37 38

/*
 * The legacy I/O space defined by the ia64 architecture supports only 65536 ports, but
 * large machines may have multiple other I/O spaces so we can't place any a priori limit
 * on IO_SPACE_LIMIT.  These additional spaces are described in ACPI.
 */
#define IO_SPACE_LIMIT		0xffffffffffffffffUL

J
John Keller 已提交
39
#define MAX_IO_SPACES_BITS		8
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47
#define MAX_IO_SPACES			(1UL << MAX_IO_SPACES_BITS)
#define IO_SPACE_BITS			24
#define IO_SPACE_SIZE			(1UL << IO_SPACE_BITS)

#define IO_SPACE_NR(port)		((port) >> IO_SPACE_BITS)
#define IO_SPACE_BASE(space)		((space) << IO_SPACE_BITS)
#define IO_SPACE_PORT(port)		((port) & (IO_SPACE_SIZE - 1))

48
#define IO_SPACE_SPARSE_ENCODING(p)	((((p) >> 2) << 12) | ((p) & 0xfff))
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

struct io_space {
	unsigned long mmio_base;	/* base in MMIO space */
	int sparse;
};

extern struct io_space io_space[];
extern unsigned int num_io_spaces;

# ifdef __KERNEL__

/*
 * All MMIO iomem cookies are in region 6; anything less is a PIO cookie:
 *	0xCxxxxxxxxxxxxxxx	MMIO cookie (return from ioremap)
 *	0x000000001SPPPPPP	PIO cookie (S=space number, P..P=port)
 *
 * ioread/writeX() uses the leading 1 in PIO cookies (PIO_OFFSET) to catch
 * code that uses bare port numbers without the prerequisite pci_iomap().
 */
#define PIO_OFFSET		(1UL << (MAX_IO_SPACES_BITS + IO_SPACE_BITS))
#define PIO_MASK		(PIO_OFFSET - 1)
#define PIO_RESERVED		__IA64_UNCACHED_OFFSET
#define HAVE_ARCH_PIO_SIZE

#include <asm/intrinsics.h>
#include <asm/page.h>
#include <asm-generic/iomap.h>

/*
 * Change virtual addresses to physical addresses and vv.
 */
static inline unsigned long
virt_to_phys (volatile void *address)
{
	return (unsigned long) address - PAGE_OFFSET;
}
A
Arnd Bergmann 已提交
85
#define virt_to_phys virt_to_phys
L
Linus Torvalds 已提交
86 87 88 89 90 91

static inline void*
phys_to_virt (unsigned long address)
{
	return (void *) (address + PAGE_OFFSET);
}
A
Arnd Bergmann 已提交
92
#define phys_to_virt phys_to_virt
L
Linus Torvalds 已提交
93 94

#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
95
extern u64 kern_mem_attribute (unsigned long phys_addr, unsigned long size);
96
extern int valid_phys_addr_range (phys_addr_t addr, size_t count); /* efi.c */
97
extern int valid_mmap_phys_addr_range (unsigned long pfn, size_t count);
L
Linus Torvalds 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

/*
 * The following two macros are deprecated and scheduled for removal.
 * Please use the PCI-DMA interface defined in <asm/pci.h> instead.
 */
#define bus_to_virt	phys_to_virt
#define virt_to_bus	virt_to_phys
#define page_to_bus	page_to_phys

# endif /* KERNEL */

/*
 * Memory fence w/accept.  This should never be used in code that is
 * not IA-64 specific.
 */
#define __ia64_mf_a()	ia64_mfa()

static inline void*
__ia64_mk_io_addr (unsigned long port)
{
	struct io_space *space;
	unsigned long offset;

	space = &io_space[IO_SPACE_NR(port)];
	port = IO_SPACE_PORT(port);
	if (space->sparse)
		offset = IO_SPACE_SPARSE_ENCODING(port);
	else
		offset = port;

	return (void *) (space->mmio_base | offset);
}

/*
 * For the in/out routines, we need to do "mf.a" _after_ doing the I/O access to ensure
 * that the access has completed before executing other I/O accesses.  Since we're doing
 * the accesses through an uncachable (UC) translation, the CPU will execute them in
 * program order.  However, we still need to tell the compiler not to shuffle them around
 * during optimization, which is why we use "volatile" pointers.
 */

139 140
#define inb inb
static inline unsigned int inb(unsigned long port)
L
Linus Torvalds 已提交
141 142 143 144 145 146 147 148 149
{
	volatile unsigned char *addr = __ia64_mk_io_addr(port);
	unsigned char ret;

	ret = *addr;
	__ia64_mf_a();
	return ret;
}

150 151
#define inw inw
static inline unsigned int inw(unsigned long port)
L
Linus Torvalds 已提交
152 153 154 155 156 157 158 159 160
{
	volatile unsigned short *addr = __ia64_mk_io_addr(port);
	unsigned short ret;

	ret = *addr;
	__ia64_mf_a();
	return ret;
}

161 162
#define inl inl
static inline unsigned int inl(unsigned long port)
L
Linus Torvalds 已提交
163 164 165 166 167 168 169 170 171
{
	volatile unsigned int *addr = __ia64_mk_io_addr(port);
	unsigned int ret;

	ret = *addr;
	__ia64_mf_a();
	return ret;
}

172 173
#define outb outb
static inline void outb(unsigned char val, unsigned long port)
L
Linus Torvalds 已提交
174 175 176 177 178 179 180
{
	volatile unsigned char *addr = __ia64_mk_io_addr(port);

	*addr = val;
	__ia64_mf_a();
}

181 182
#define outw outw
static inline void outw(unsigned short val, unsigned long port)
L
Linus Torvalds 已提交
183 184 185 186 187 188 189
{
	volatile unsigned short *addr = __ia64_mk_io_addr(port);

	*addr = val;
	__ia64_mf_a();
}

190 191
#define outl outl
static inline void outl(unsigned int val, unsigned long port)
L
Linus Torvalds 已提交
192 193 194 195 196 197 198
{
	volatile unsigned int *addr = __ia64_mk_io_addr(port);

	*addr = val;
	__ia64_mf_a();
}

199 200
#define insb insb
static inline void insb(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
201 202 203 204
{
	unsigned char *dp = dst;

	while (count--)
205
		*dp++ = inb(port);
L
Linus Torvalds 已提交
206 207
}

208 209
#define insw insw
static inline void insw(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
210 211 212 213
{
	unsigned short *dp = dst;

	while (count--)
214
		put_unaligned(inw(port), dp++);
L
Linus Torvalds 已提交
215 216
}

217 218
#define insl insl
static inline void insl(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
219 220 221 222
{
	unsigned int *dp = dst;

	while (count--)
223
		put_unaligned(inl(port), dp++);
L
Linus Torvalds 已提交
224 225
}

226 227 228
#define outsb outsb
static inline void outsb(unsigned long port, const void *src,
		unsigned long count)
L
Linus Torvalds 已提交
229 230 231 232
{
	const unsigned char *sp = src;

	while (count--)
233
		outb(*sp++, port);
L
Linus Torvalds 已提交
234 235
}

236 237 238
#define outsw outsw
static inline void outsw(unsigned long port, const void *src,
		unsigned long count)
L
Linus Torvalds 已提交
239 240 241 242
{
	const unsigned short *sp = src;

	while (count--)
243
		outw(get_unaligned(sp++), port);
L
Linus Torvalds 已提交
244 245
}

246 247 248
#define outsl outsl
static inline void outsl(unsigned long port, const void *src,
		unsigned long count)
L
Linus Torvalds 已提交
249 250 251 252
{
	const unsigned int *sp = src;

	while (count--)
253
		outl(get_unaligned(sp++), port);
L
Linus Torvalds 已提交
254 255
}

256 257
# ifdef __KERNEL__

258
extern void __iomem * ioremap(unsigned long offset, unsigned long size);
259
extern void __iomem * ioremap_uc(unsigned long offset, unsigned long size);
260
extern void iounmap (volatile void __iomem *addr);
L
Len Brown 已提交
261 262 263 264
static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size)
{
	return ioremap(phys_addr, size);
}
A
Arnd Bergmann 已提交
265
#define ioremap ioremap
D
Dan Williams 已提交
266
#define ioremap_cache ioremap_cache
267
#define ioremap_uc ioremap_uc
A
Arnd Bergmann 已提交
268
#define iounmap iounmap
L
Linus Torvalds 已提交
269 270 271 272 273 274 275 276

/*
 * String version of IO memory access ops:
 */
extern void memcpy_fromio(void *dst, const volatile void __iomem *src, long n);
extern void memcpy_toio(volatile void __iomem *dst, const void *src, long n);
extern void memset_io(volatile void __iomem *s, int c, long n);

A
Arnd Bergmann 已提交
277 278 279 280 281 282
#define memcpy_fromio memcpy_fromio
#define memcpy_toio memcpy_toio
#define memset_io memset_io
#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
#define xlate_dev_mem_ptr xlate_dev_mem_ptr
#include <asm-generic/io.h>
283
#undef PCI_IOBASE
A
Arnd Bergmann 已提交
284

L
Linus Torvalds 已提交
285 286 287
# endif /* __KERNEL__ */

#endif /* _ASM_IA64_IO_H */