1/* 2 * $Id: io.h,v 1.1.1.1 2008/10/15 03:29:17 james26_jang Exp $ 3 */ 4#ifndef __SPARC_IO_H 5#define __SPARC_IO_H 6 7#include <linux/kernel.h> 8#include <linux/types.h> 9#include <linux/ioport.h> /* struct resource */ 10 11#include <asm/page.h> /* IO address mapping routines need this */ 12#include <asm/system.h> 13 14#define virt_to_bus virt_to_phys 15#define bus_to_virt phys_to_virt 16#define page_to_phys(page) ((((page) - mem_map) << PAGE_SHIFT)+phys_base) 17 18static __inline__ u32 flip_dword (u32 d) 19{ 20 return ((d&0xff)<<24) | (((d>>8)&0xff)<<16) | (((d>>16)&0xff)<<8)| ((d>>24)&0xff); 21} 22 23static __inline__ u16 flip_word (u16 d) 24{ 25 return ((d&0xff) << 8) | ((d>>8)&0xff); 26} 27 28/* 29 * Memory mapped I/O to PCI 30 */ 31static __inline__ u8 readb(unsigned long addr) 32{ 33 return *(volatile u8 *)addr; 34} 35 36static __inline__ u16 readw(unsigned long addr) 37{ 38 return flip_word(*(volatile u16 *)addr); 39} 40 41static __inline__ u32 readl(unsigned long addr) 42{ 43 return flip_dword(*(volatile u32 *)addr); 44} 45 46static __inline__ void writeb(u8 b, unsigned long addr) 47{ 48 *(volatile u8 *)addr = b; 49} 50 51static __inline__ void writew(u16 b, unsigned long addr) 52{ 53 *(volatile u16 *)addr = flip_word(b); 54} 55 56static __inline__ void writel(u32 b, unsigned long addr) 57{ 58 *(volatile u32 *)addr = flip_dword(b); 59} 60 61/* Now the 'raw' versions. */ 62static __inline__ u8 __raw_readb(unsigned long addr) 63{ 64 return *(volatile u8 *)addr; 65} 66 67static __inline__ u16 __raw_readw(unsigned long addr) 68{ 69 return *(volatile u16 *)addr; 70} 71 72static __inline__ u32 __raw_readl(unsigned long addr) 73{ 74 return *(volatile u32 *)addr; 75} 76 77static __inline__ void __raw_writeb(u8 b, unsigned long addr) 78{ 79 *(volatile u8 *)addr = b; 80} 81 82static __inline__ void __raw_writew(u16 b, unsigned long addr) 83{ 84 *(volatile u16 *)addr = b; 85} 86 87static __inline__ void __raw_writel(u32 b, unsigned long addr) 88{ 89 *(volatile u32 *)addr = b; 90} 91 92/* 93 * I/O space operations 94 * 95 * Arrangement on a Sun is somewhat complicated. 96 * 97 * First of all, we want to use standard Linux drivers 98 * for keyboard, PC serial, etc. These drivers think 99 * they access I/O space and use inb/outb. 100 * On the other hand, EBus bridge accepts PCI *memory* 101 * cycles and converts them into ISA *I/O* cycles. 102 * Ergo, we want inb & outb to generate PCI memory cycles. 103 * 104 * If we want to issue PCI *I/O* cycles, we do this 105 * with a low 64K fixed window in PCIC. This window gets 106 * mapped somewhere into virtual kernel space and we 107 * can use inb/outb again. 108 */ 109#define inb_local(addr) readb(addr) 110#define inb(addr) readb(addr) 111#define inw(addr) readw(addr) 112#define inl(addr) readl(addr) 113#define inb_p(addr) readb(addr) 114 115#define outb_local(b, addr) writeb(b, addr) 116#define outb(b, addr) writeb(b, addr) 117#define outw(b, addr) writew(b, addr) 118#define outl(b, addr) writel(b, addr) 119#define outb_p(b, addr) writeb(b, addr) 120 121extern void outsb(unsigned long addr, const void *src, unsigned long cnt); 122extern void outsw(unsigned long addr, const void *src, unsigned long cnt); 123extern void outsl(unsigned long addr, const void *src, unsigned long cnt); 124extern void insb(unsigned long addr, void *dst, unsigned long count); 125extern void insw(unsigned long addr, void *dst, unsigned long count); 126extern void insl(unsigned long addr, void *dst, unsigned long count); 127 128#define IO_SPACE_LIMIT 0xffffffff 129 130/* 131 * SBus accessors. 132 * 133 * SBus has only one, memory mapped, I/O space. 134 * We do not need to flip bytes for SBus of course. 135 */ 136static __inline__ u8 _sbus_readb(unsigned long addr) 137{ 138 return *(volatile u8 *)addr; 139} 140 141static __inline__ u16 _sbus_readw(unsigned long addr) 142{ 143 return *(volatile u16 *)addr; 144} 145 146static __inline__ u32 _sbus_readl(unsigned long addr) 147{ 148 return *(volatile u32 *)addr; 149} 150 151static __inline__ void _sbus_writeb(u8 b, unsigned long addr) 152{ 153 *(volatile u8 *)addr = b; 154} 155 156static __inline__ void _sbus_writew(u16 b, unsigned long addr) 157{ 158 *(volatile u16 *)addr = b; 159} 160 161static __inline__ void _sbus_writel(u32 b, unsigned long addr) 162{ 163 *(volatile u32 *)addr = b; 164} 165 166#define sbus_readb(a) _sbus_readb((unsigned long)(a)) 167#define sbus_readw(a) _sbus_readw((unsigned long)(a)) 168#define sbus_readl(a) _sbus_readl((unsigned long)(a)) 169#define sbus_writeb(v, a) _sbus_writeb(v, (unsigned long)(a)) 170#define sbus_writew(v, a) _sbus_writew(v, (unsigned long)(a)) 171#define sbus_writel(v, a) _sbus_writel(v, (unsigned long)(a)) 172 173static inline void *sbus_memset_io(void *__dst, int c, __kernel_size_t n) 174{ 175 unsigned long dst = (unsigned long)__dst; 176 177 while(n--) { 178 sbus_writeb(c, dst); 179 dst++; 180 } 181 return (void *) dst; 182} 183 184#ifdef __KERNEL__ 185 186/* 187 * Bus number may be embedded in the higher bits of the physical address. 188 * This is why we have no bus number argument to ioremap(). 189 */ 190extern void *ioremap(unsigned long offset, unsigned long size); 191#define ioremap_nocache(X,Y) ioremap((X),(Y)) 192extern void iounmap(void *addr); 193 194/* P3: talk davem into dropping "name" argument in favor of res->name */ 195/* 196 * Bus number may be in res->flags... somewhere. 197 */ 198extern unsigned long sbus_ioremap(struct resource *res, unsigned long offset, 199 unsigned long size, char *name); 200extern void sbus_iounmap(unsigned long vaddr, unsigned long size); 201 202 203#define virt_to_phys(x) __pa((unsigned long)(x)) 204#define phys_to_virt(x) __va((unsigned long)(x)) 205 206/* 207 * At the moment, we do not use CMOS_READ anywhere outside of rtc.c, 208 * so rtc_port is static in it. This should not change unless a new 209 * hardware pops up. 210 */ 211#define RTC_PORT(x) (rtc_port + (x)) 212#define RTC_ALWAYS_BCD 0 213 214/* Nothing to do */ 215/* P3: Only IDE DMA may need these. */ 216 217#define dma_cache_inv(_start,_size) do { } while (0) 218#define dma_cache_wback(_start,_size) do { } while (0) 219#define dma_cache_wback_inv(_start,_size) do { } while (0) 220 221#endif 222 223#endif /* !(__SPARC_IO_H) */ 224