162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci NinjaSCSI I/O funtions 362306a36Sopenharmony_ci By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp> 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci This software may be used and distributed according to the terms of 662306a36Sopenharmony_ci the GNU General Public License. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* $Id: nsp_io.h,v 1.3 2003/08/04 21:15:26 elca Exp $ */ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef __NSP_IO_H__ 1362306a36Sopenharmony_ci#define __NSP_IO_H__ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistatic inline void nsp_write(unsigned int base, 1662306a36Sopenharmony_ci unsigned int index, 1762306a36Sopenharmony_ci unsigned char val); 1862306a36Sopenharmony_cistatic inline unsigned char nsp_read(unsigned int base, 1962306a36Sopenharmony_ci unsigned int index); 2062306a36Sopenharmony_cistatic inline void nsp_index_write(unsigned int BaseAddr, 2162306a36Sopenharmony_ci unsigned int Register, 2262306a36Sopenharmony_ci unsigned char Value); 2362306a36Sopenharmony_cistatic inline unsigned char nsp_index_read(unsigned int BaseAddr, 2462306a36Sopenharmony_ci unsigned int Register); 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/******************************************************************* 2762306a36Sopenharmony_ci * Basic IO 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistatic inline void nsp_write(unsigned int base, 3162306a36Sopenharmony_ci unsigned int index, 3262306a36Sopenharmony_ci unsigned char val) 3362306a36Sopenharmony_ci{ 3462306a36Sopenharmony_ci outb(val, (base + index)); 3562306a36Sopenharmony_ci} 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cistatic inline unsigned char nsp_read(unsigned int base, 3862306a36Sopenharmony_ci unsigned int index) 3962306a36Sopenharmony_ci{ 4062306a36Sopenharmony_ci return inb(base + index); 4162306a36Sopenharmony_ci} 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/********************************************************************** 4562306a36Sopenharmony_ci * Indexed IO 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_cistatic inline unsigned char nsp_index_read(unsigned int BaseAddr, 4862306a36Sopenharmony_ci unsigned int Register) 4962306a36Sopenharmony_ci{ 5062306a36Sopenharmony_ci outb(Register, BaseAddr + INDEXREG); 5162306a36Sopenharmony_ci return inb(BaseAddr + DATAREG); 5262306a36Sopenharmony_ci} 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_cistatic inline void nsp_index_write(unsigned int BaseAddr, 5562306a36Sopenharmony_ci unsigned int Register, 5662306a36Sopenharmony_ci unsigned char Value) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci outb(Register, BaseAddr + INDEXREG); 5962306a36Sopenharmony_ci outb(Value, BaseAddr + DATAREG); 6062306a36Sopenharmony_ci} 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/********************************************************************* 6362306a36Sopenharmony_ci * fifo func 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* read 8 bit FIFO */ 6762306a36Sopenharmony_cistatic inline void nsp_multi_read_1(unsigned int BaseAddr, 6862306a36Sopenharmony_ci unsigned int Register, 6962306a36Sopenharmony_ci void *buf, 7062306a36Sopenharmony_ci unsigned long count) 7162306a36Sopenharmony_ci{ 7262306a36Sopenharmony_ci insb(BaseAddr + Register, buf, count); 7362306a36Sopenharmony_ci} 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_cistatic inline void nsp_fifo8_read(unsigned int base, 7662306a36Sopenharmony_ci void *buf, 7762306a36Sopenharmony_ci unsigned long count) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci /*nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx", buf, count);*/ 8062306a36Sopenharmony_ci nsp_multi_read_1(base, FIFODATA, buf, count); 8162306a36Sopenharmony_ci} 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/*--------------------------------------------------------------*/ 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* read 16 bit FIFO */ 8662306a36Sopenharmony_cistatic inline void nsp_multi_read_2(unsigned int BaseAddr, 8762306a36Sopenharmony_ci unsigned int Register, 8862306a36Sopenharmony_ci void *buf, 8962306a36Sopenharmony_ci unsigned long count) 9062306a36Sopenharmony_ci{ 9162306a36Sopenharmony_ci insw(BaseAddr + Register, buf, count); 9262306a36Sopenharmony_ci} 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistatic inline void nsp_fifo16_read(unsigned int base, 9562306a36Sopenharmony_ci void *buf, 9662306a36Sopenharmony_ci unsigned long count) 9762306a36Sopenharmony_ci{ 9862306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*2", buf, count); 9962306a36Sopenharmony_ci nsp_multi_read_2(base, FIFODATA, buf, count); 10062306a36Sopenharmony_ci} 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ci/*--------------------------------------------------------------*/ 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/* read 32bit FIFO */ 10562306a36Sopenharmony_cistatic inline void nsp_multi_read_4(unsigned int BaseAddr, 10662306a36Sopenharmony_ci unsigned int Register, 10762306a36Sopenharmony_ci void *buf, 10862306a36Sopenharmony_ci unsigned long count) 10962306a36Sopenharmony_ci{ 11062306a36Sopenharmony_ci insl(BaseAddr + Register, buf, count); 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic inline void nsp_fifo32_read(unsigned int base, 11462306a36Sopenharmony_ci void *buf, 11562306a36Sopenharmony_ci unsigned long count) 11662306a36Sopenharmony_ci{ 11762306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count); 11862306a36Sopenharmony_ci nsp_multi_read_4(base, FIFODATA, buf, count); 11962306a36Sopenharmony_ci} 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/*----------------------------------------------------------*/ 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/* write 8bit FIFO */ 12462306a36Sopenharmony_cistatic inline void nsp_multi_write_1(unsigned int BaseAddr, 12562306a36Sopenharmony_ci unsigned int Register, 12662306a36Sopenharmony_ci void *buf, 12762306a36Sopenharmony_ci unsigned long count) 12862306a36Sopenharmony_ci{ 12962306a36Sopenharmony_ci outsb(BaseAddr + Register, buf, count); 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_cistatic inline void nsp_fifo8_write(unsigned int base, 13362306a36Sopenharmony_ci void *buf, 13462306a36Sopenharmony_ci unsigned long count) 13562306a36Sopenharmony_ci{ 13662306a36Sopenharmony_ci nsp_multi_write_1(base, FIFODATA, buf, count); 13762306a36Sopenharmony_ci} 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci/*---------------------------------------------------------*/ 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci/* write 16bit FIFO */ 14262306a36Sopenharmony_cistatic inline void nsp_multi_write_2(unsigned int BaseAddr, 14362306a36Sopenharmony_ci unsigned int Register, 14462306a36Sopenharmony_ci void *buf, 14562306a36Sopenharmony_ci unsigned long count) 14662306a36Sopenharmony_ci{ 14762306a36Sopenharmony_ci outsw(BaseAddr + Register, buf, count); 14862306a36Sopenharmony_ci} 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistatic inline void nsp_fifo16_write(unsigned int base, 15162306a36Sopenharmony_ci void *buf, 15262306a36Sopenharmony_ci unsigned long count) 15362306a36Sopenharmony_ci{ 15462306a36Sopenharmony_ci nsp_multi_write_2(base, FIFODATA, buf, count); 15562306a36Sopenharmony_ci} 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/*---------------------------------------------------------*/ 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci/* write 32bit FIFO */ 16062306a36Sopenharmony_cistatic inline void nsp_multi_write_4(unsigned int BaseAddr, 16162306a36Sopenharmony_ci unsigned int Register, 16262306a36Sopenharmony_ci void *buf, 16362306a36Sopenharmony_ci unsigned long count) 16462306a36Sopenharmony_ci{ 16562306a36Sopenharmony_ci outsl(BaseAddr + Register, buf, count); 16662306a36Sopenharmony_ci} 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_cistatic inline void nsp_fifo32_write(unsigned int base, 16962306a36Sopenharmony_ci void *buf, 17062306a36Sopenharmony_ci unsigned long count) 17162306a36Sopenharmony_ci{ 17262306a36Sopenharmony_ci nsp_multi_write_4(base, FIFODATA, buf, count); 17362306a36Sopenharmony_ci} 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci/*====================================================================*/ 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_cistatic inline void nsp_mmio_write(unsigned long base, 17962306a36Sopenharmony_ci unsigned int index, 18062306a36Sopenharmony_ci unsigned char val) 18162306a36Sopenharmony_ci{ 18262306a36Sopenharmony_ci unsigned char *ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + index); 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci writeb(val, ptr); 18562306a36Sopenharmony_ci} 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_cistatic inline unsigned char nsp_mmio_read(unsigned long base, 18862306a36Sopenharmony_ci unsigned int index) 18962306a36Sopenharmony_ci{ 19062306a36Sopenharmony_ci unsigned char *ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + index); 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci return readb(ptr); 19362306a36Sopenharmony_ci} 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci/*-----------*/ 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_cistatic inline unsigned char nsp_mmio_index_read(unsigned long base, 19862306a36Sopenharmony_ci unsigned int reg) 19962306a36Sopenharmony_ci{ 20062306a36Sopenharmony_ci unsigned char *index_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + INDEXREG); 20162306a36Sopenharmony_ci unsigned char *data_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + DATAREG); 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci writeb((unsigned char)reg, index_ptr); 20462306a36Sopenharmony_ci return readb(data_ptr); 20562306a36Sopenharmony_ci} 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_cistatic inline void nsp_mmio_index_write(unsigned long base, 20862306a36Sopenharmony_ci unsigned int reg, 20962306a36Sopenharmony_ci unsigned char val) 21062306a36Sopenharmony_ci{ 21162306a36Sopenharmony_ci unsigned char *index_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + INDEXREG); 21262306a36Sopenharmony_ci unsigned char *data_ptr = (unsigned char *)(base + NSP_MMIO_OFFSET + DATAREG); 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci writeb((unsigned char)reg, index_ptr); 21562306a36Sopenharmony_ci writeb(val, data_ptr); 21662306a36Sopenharmony_ci} 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci/* read 32bit FIFO */ 21962306a36Sopenharmony_cistatic inline void nsp_mmio_multi_read_4(unsigned long base, 22062306a36Sopenharmony_ci unsigned int Register, 22162306a36Sopenharmony_ci void *buf, 22262306a36Sopenharmony_ci unsigned long count) 22362306a36Sopenharmony_ci{ 22462306a36Sopenharmony_ci unsigned long *ptr = (unsigned long *)(base + Register); 22562306a36Sopenharmony_ci unsigned long *tmp = (unsigned long *)buf; 22662306a36Sopenharmony_ci int i; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "base 0x%0lx ptr 0x%p",base,ptr); 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci for (i = 0; i < count; i++) { 23162306a36Sopenharmony_ci *tmp = readl(ptr); 23262306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "<%d,%p,%p,%lx>", i, ptr, tmp, *tmp); 23362306a36Sopenharmony_ci tmp++; 23462306a36Sopenharmony_ci } 23562306a36Sopenharmony_ci} 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_cistatic inline void nsp_mmio_fifo32_read(unsigned int base, 23862306a36Sopenharmony_ci void *buf, 23962306a36Sopenharmony_ci unsigned long count) 24062306a36Sopenharmony_ci{ 24162306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count); 24262306a36Sopenharmony_ci nsp_mmio_multi_read_4(base, FIFODATA, buf, count); 24362306a36Sopenharmony_ci} 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_cistatic inline void nsp_mmio_multi_write_4(unsigned long base, 24662306a36Sopenharmony_ci unsigned int Register, 24762306a36Sopenharmony_ci void *buf, 24862306a36Sopenharmony_ci unsigned long count) 24962306a36Sopenharmony_ci{ 25062306a36Sopenharmony_ci unsigned long *ptr = (unsigned long *)(base + Register); 25162306a36Sopenharmony_ci unsigned long *tmp = (unsigned long *)buf; 25262306a36Sopenharmony_ci int i; 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "base 0x%0lx ptr 0x%p",base,ptr); 25562306a36Sopenharmony_ci 25662306a36Sopenharmony_ci for (i = 0; i < count; i++) { 25762306a36Sopenharmony_ci writel(*tmp, ptr); 25862306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "<%d,%p,%p,%lx>", i, ptr, tmp, *tmp); 25962306a36Sopenharmony_ci tmp++; 26062306a36Sopenharmony_ci } 26162306a36Sopenharmony_ci} 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_cistatic inline void nsp_mmio_fifo32_write(unsigned int base, 26462306a36Sopenharmony_ci void *buf, 26562306a36Sopenharmony_ci unsigned long count) 26662306a36Sopenharmony_ci{ 26762306a36Sopenharmony_ci //nsp_dbg(NSP_DEBUG_DATA_IO, "buf=0x%p, count=0x%lx*4", buf, count); 26862306a36Sopenharmony_ci nsp_mmio_multi_write_4(base, FIFODATA, buf, count); 26962306a36Sopenharmony_ci} 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci#endif 27462306a36Sopenharmony_ci/* end */ 275