diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2006-10-06 21:16:16 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2006-10-06 21:16:16 +0000 |
commit | 52fbcc0a30217287f3923c2d4d95e147f2f82b50 (patch) | |
tree | b05fc236e57650fe31cd0901d6cb0dc736a44540 /sys | |
parent | f2984aabfd358ae2731013df5d571a596cb9a5eb (diff) |
Incomplete bits for an OpenBSD/landisk port to the I/O DATA USL-5P appliances,
mickey@ has the other part.
Diffstat (limited to 'sys')
52 files changed, 4025 insertions, 0 deletions
diff --git a/sys/arch/landisk/Makefile b/sys/arch/landisk/Makefile new file mode 100644 index 00000000000..80456e14c98 --- /dev/null +++ b/sys/arch/landisk/Makefile @@ -0,0 +1,28 @@ +# $OpenBSD: Makefile,v 1.1 2006/10/06 21:16:15 miod Exp $ +# $NetBSD: Makefile,v 1.1 2006/09/01 21:26:18 uwe Exp $ + +# Makefile for landisk tags file and boot blocks + +TLANDISK= ../landisk/tags +SLANDISK= ../landisk/landisk/*.[ch] ../landisk/include/*.h +ALANDISK= ../landisk/landisk/*.[sS] + +# Directories in which to place tags links +DLANDISK= landisk include + +.include "../../kern/Make.tags.inc" + +tags: + -ctags -wdtf ${TLANDISK} ${SLANDISK} ${COMM} + egrep "^ENTRY(.*)|^ALTENTRY(.*)" ${ALANDISK} | \ + sed "s;\([^:]*\):\([^(]*\)(\([^, )]*\)\(.*\);\3 \1 /^\2(\3\4$$/;" \ + >> ${TLANDISK} + sort -o ${TLANDISK} ${TLANDISK} + +links: + -for i in ${DLANDISK}; do \ + (cd $$i && rm -f tags; ln -s ../tags tags); done + +SUBDIR= stand + +.include <bsd.subdir.mk> diff --git a/sys/arch/landisk/compile/.cvsignore b/sys/arch/landisk/compile/.cvsignore new file mode 100644 index 00000000000..b72af3039e6 --- /dev/null +++ b/sys/arch/landisk/compile/.cvsignore @@ -0,0 +1,2 @@ +GENERIC +RAMDISK diff --git a/sys/arch/landisk/conf/GENERIC b/sys/arch/landisk/conf/GENERIC new file mode 100644 index 00000000000..6986a30abc4 --- /dev/null +++ b/sys/arch/landisk/conf/GENERIC @@ -0,0 +1,91 @@ +# $OpenBSD: GENERIC,v 1.1 2006/10/06 21:16:15 miod Exp $ +# +# For further information on compiling OpenBSD kernels, see the config(8) +# man page. +# +# For further information on hardware support for this architecture, see +# the intro(4) man page. For further information about kernel options +# for this architecture, see the options(4) man page. For an explanation +# of each device driver in this file see the section 4 man page for the +# device. + +machine landisk sh +include "../../../conf/GENERIC" +maxusers 32 # estimated number of users + +option SH4 # processor family; MANDATORY +option SH7751R # processor type; MANDATORY + +# CPU-related options. +option PCLOCK=33333333 # 33.33MHz clock +option DONT_INIT_BSC +#option DONT_INIT_PCIBSC + +# Cache options. +option SH4_CACHE_DISABLE_EMODE # disable extended (2x larger) mode + +#config bsd swap generic +config bsd root on wd0a + +mainbus0 at root +cpu0 at mainbus? + +# PCI bus support +shpcic* at mainbus? # SH7751 PCIC +pci0 at shpcic? bus ? + +# SH bus +shb* at mainbus? + +# ob-board I/O bus +obio0 at mainbus? + +# Serial Devices +option SCIFCONSOLE +option SCIFCN_SPEED=9600 +scif0 at shb? + +clock0 at shb? + +wdc0 at obio? port 0x14000000 irq 10 # CF +wd* at wdc? flags 0x0000 + +# Network Interfaces + +# PCI network interfaces +re* at pci? dev ? function ? # Realtek 8139C+/8169/8169S/8110S +rl* at pci? dev ? function ? # Realtek 8129/8139 + +# MII/PHY support +rgephy* at mii? phy ? +rlphy* at mii? phy ? # Realtek 8139/8201L PHYs +urlphy* at mii? phy ? # Realtek RTL8150L internal PHYs +ukphy* at mii? phy ? # generic unknown PHYs + +# USB Controller and Devices + +# PCI USB controllers +ehci* at pci? dev ? function ? # Enhanced Host Controller +ohci* at pci? dev ? function ? # Open Host Controller + +# USB bus support +usb* at ehci? +usb* at ohci? + +# USB Hubs +uhub* at usb? +uhub* at uhub? port ? configuration ? interface ? + +# USB HID device +uhidev* at uhub? port ? configuration ? interface ? + +# USB Mass Storage +umass* at uhub? port ? configuration ? interface ? +scsibus* at umass? +atapiscsi* at umass? + +sd* at scsibus? target ? lun ? # SCSI disk drives +cd* at scsibus? target ? lun ? # SCSI CD-ROM drives + +# USB Generic driver +ugen* at uhub? port ? diff --git a/sys/arch/landisk/conf/Makefile.landisk b/sys/arch/landisk/conf/Makefile.landisk new file mode 100644 index 00000000000..490dbb3b6c4 --- /dev/null +++ b/sys/arch/landisk/conf/Makefile.landisk @@ -0,0 +1,210 @@ +# $OpenBSD: Makefile.landisk,v 1.1 2006/10/06 21:16:15 miod Exp $ +# +# Makefile for OpenBSD/landisk +# +# This makefile is constructed from a machine description: +# config machineid +# Most changes should be made in the machine description +# /sys/arch/landisk/conf/``machineid'' +# after which you should do +# config machineid +# Machine generic makefile changes should be made in +# /sys/arch/landisk/conf/Makefile.landisk +# after which config should be rerun for all machines of that type. +# +# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE +# IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING +# +# -DTRACE compile in kernel tracing hooks +# -DQUOTA compile in file system quotas +# +.SUFFIXES: .S .c .o + +# DEBUG is set to -g if debugging. +# PROF is set to -pg if profiling. + +.include <bsd.own.mk> + +MKDEP?= mkdep +STRIP?= strip +SIZE?= size + +# source tree is located via $S relative to the compilation directory +.ifndef S +S!= cd ../../../..; pwd +.endif +LANDISK= $S/arch/landisk +SH= $S/arch/sh + +INCLUDES= -I. -I$S/arch -I$S -nostdinc +CPPFLAGS= ${INCLUDES} ${IDENT} -D_KERNEL -Dlandisk +CWARNFLAGS= -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes \ + -Wno-uninitialized -Wno-format -Wno-main \ + -Wstack-larger-than-2047 +CMACHFLAGS= -m4-nofpu \ + -fno-builtin-printf -fno-builtin-log -fno-builtin-main +.if ${IDENT:M-DNO_PROPOLICE} +CMACHFLAGS+= -fno-stack-protector +.else +# to prevent the sky from falling on our heads +CMACHFLAGS+= -fno-stack-protector +.endif +COPTS?= -O2 +CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE} +AFLAGS= -x assembler-with-cpp -traditional-cpp -D_LOCORE -Wa,-little +LINKFLAGS= -N -Ttext 0x8c001000 -e start --warn-common +STRIPFLAGS= -g -X -x + +HOSTCC?= ${CC} +HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//} +HOSTED_CFLAGS= ${CFLAGS} + +### find out what to use for libkern +.include "$S/lib/libkern/Makefile.inc" +.ifndef PROF +LIBKERN= ${KERNLIB} +.else +LIBKERN= ${KERNLIB_PROF} +.endif + +### find out what to use for libcompat +.include "$S/compat/common/Makefile.inc" +.ifndef PROF +LIBCOMPAT= ${COMPATLIB} +.else +LIBCOMPAT= ${COMPATLIB_PROF} +.endif + +# compile rules: rules are named ${TYPE}_${SUFFIX}${CONFIG_DEP} +# where TYPE is NORMAL, DRIVER, or PROFILE}; SUFFIX is the file suffix, +# capitalized (e.g. C for a .c file), and CONFIG_DEP is _C if the file +# is marked as config-dependent. + +USRLAND_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< +USRLAND_C_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $< + +NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< +NORMAL_C_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $< + +DRIVER_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $< +DRIVER_C_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} ${PARAM} -c $< + +NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} -c $< +NORMAL_S_C= ${AS} ${COPTS} ${PARAM} $< -o $@ + + +%OBJS + +%CFILES + +%SFILES + +# load lines for config "xxx" will be emitted as: +# xxx: ${SYSTEM_DEP} swapxxx.o +# ${SYSTEM_LD_HEAD} +# ${SYSTEM_LD} swapxxx.o +# ${SYSTEM_LD_TAIL} +SYSTEM_OBJ= locore.o param.o ioconf.o ${OBJS} ${LIBKERN} ${LIBCOMPAT} +SYSTEM_DEP= Makefile ${SYSTEM_OBJ} +SYSTEM_LD_HEAD= rm -f $@ +SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_OBJ}' vers.o; \ + ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_OBJ} vers.o +SYSTEM_LD_TAIL= @${SIZE} $@; chmod 755 $@ + +DEBUG?= +.if ${DEBUG} == "-g" +LINKFLAGS+= -X +SYSTEM_LD_TAIL+=; \ + echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \ + echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \ + ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb +.else +LINKFLAGS+= -S -x +.endif + +%LOAD + +assym.h: $S/kern/genassym.sh \ + ${SH}/sh/genassym.cf Makefile + cat ${SH}/sh/genassym.cf | \ + sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} \ + > assym.h.tmp && \ + mv -f assym.h.tmp assym.h + +param.c: $S/conf/param.c + rm -f param.c + cp $S/conf/param.c . + +param.o: param.c Makefile + ${NORMAL_C_C} + +ioconf.o: ioconf.c + ${NORMAL_C} + +newvers: ${SYSTEM_DEP} ${SYSTEM_SWAP_DEP} + sh $S/conf/newvers.sh + ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c + +clean:: + rm -f eddep *bsd bsd.gdb tags *.[io] [a-z]*.s \ + [Ee]rrs linterrs makelinks genassym genassym.o assym.h + +lint: + @lint -hbxncez -DGENERIC -Dvolatile= ${CPPFLAGS} -UKGDB ${CFILES} \ + ioconf.c param.c | \ + grep -v 'static function .* unused' + +tags: + @echo "see $S/kern/Makefile for tags" + +links: + egrep '#if' ${CFILES} | sed -f $S/conf/defines | \ + sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink + echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \ + sort -u | comm -23 - dontlink | \ + sed 's,../.*/\(.*.o\),rm -f \1; ln -s ../GENERIC/\1 \1,' > makelinks + sh makelinks && rm -f dontlink + +SRCS= ${LANDISK}/landisk/locore.S \ + param.c ioconf.c ${CFILES} ${SFILES} +depend:: .depend +.depend: ${SRCS} assym.h param.c + ${MKDEP} ${AFLAGS} ${CPPFLAGS} ${LANDISK}/landisk/locore.S + ${MKDEP} -a ${CFLAGS} ${CPPFLAGS} param.c ioconf.c ${CFILES} +.if ${SFILES} != "" + ${MKDEP} -a ${AFLAGS} ${CPPFLAGS} ${SFILES} +.endif + cat ${SH}/sh/genassym.cf | \ + sh $S/kern/genassym.sh ${MKDEP} -f assym.dep ${CFLAGS} ${CPPFLAGS} + @sed -e 's/.*\.o:.* /assym.h: /' < assym.dep >> .depend + @rm -f assym.dep + +# depend on root or device configuration +autoconf.o conf.o: Makefile + +# depend on network or filesystem configuration +uipc_proto.o vfs_conf.o: Makefile + +# depend on maxusers +assym.h machdep.o: Makefile + +# depend on CPU configuration +locore.o machdep.o: Makefile + + +locore.o: ${LANDISK}/landisk/locore.S assym.h + ${NORMAL_S} + +# The install target can be redefined by putting a +# install-kernel-${MACHINE_NAME} target into /etc/mk.conf +MACHINE_NAME!= uname -n +install: install-kernel-${MACHINE_NAME} +.if !target(install-kernel-${MACHINE_NAME}}) +install-kernel-${MACHINE_NAME}: + rm -f /obsd + ln /bsd /obsd + cp bsd /nbsd + mv /nbsd /bsd +.endif + +%RULES diff --git a/sys/arch/landisk/conf/files.landisk b/sys/arch/landisk/conf/files.landisk new file mode 100644 index 00000000000..b5164cdf8bc --- /dev/null +++ b/sys/arch/landisk/conf/files.landisk @@ -0,0 +1,104 @@ +# $OpenBSD: files.landisk,v 1.1 2006/10/06 21:16:15 miod Exp $ +# $NetBSD: files.landisk,v 1.2 2006/09/07 01:55:02 uwe Exp $ + +# maxpartitions must be first item in files.${MACHINE} +maxpartitions 16 + +maxusers 2 16 64 + +major {wd = 0} + +#defparam opt_memsize.h IOM_ROM_BEGIN IOM_ROM_SIZE IOM_RAM_BEGIN IOM_RAM_SIZE + +file arch/landisk/landisk/autoconf.c +file arch/landisk/landisk/bus_dma.c +file arch/landisk/landisk/clock_machdep.c +file arch/landisk/landisk/conf.c +file arch/landisk/landisk/consinit.c +file arch/landisk/landisk/disksubr.c disk +file arch/landisk/landisk/intr.c +file arch/landisk/landisk/machdep.c + +# +# System bus types +# + +define mainbus {} +device mainbus: pcibus, mainbus +attach mainbus at root +file arch/landisk/landisk/mainbus.c mainbus + +device cpu +attach cpu at mainbus +file arch/sh/sh/cpu.c cpu + +# +# Machine-independent SCSI drivers +# +include "scsi/files.scsi" + +# +# Machine-independent ATA drivers +# +include "dev/ata/files.ata" +include "dev/atapiscsi/files.atapiscsi" + +# +# Machine-independent I2O drivers +# +include "dev/i2o/files.i2o" + +#include "dev/wscons/files.wscons" +#include "dev/wsfont/files.wsfont" +#include "dev/rasops/files.rasops" + +# +# PCI bus +# +include "dev/mii/files.mii" +include "dev/pci/files.pci" +include "arch/sh/conf/files.shpcic" + +file arch/landisk/landisk/shpcic_machdep.c shpcic + +# +# USB drivers +# +include "dev/usb/files.usb" + +# +# SH bus +# +include "arch/sh/conf/files.shb" + +# Ricoh RS5C313 Real Time Clock +device clock +attach clock at shb +file arch/landisk/dev/rs5c313.c clock + +# +# on-board I/O bus +# +define obio { [port = -1], [size = 0], [iomem = -1], [iosiz = 0], [irq = -1] } + +device obio: obio +attach obio at mainbus +file arch/landisk/dev/obio.c obio needs-flag + +attach wdc at obio with wdc_obio +file arch/landisk/dev/wdc_obio.c wdc_obio needs-flag + +define button +file arch/landisk/dev/button.c button + +device btn: button +attach btn at obio with btn_obio +file arch/landisk/dev/btn_obio.c btn_obio needs-flag + +device pwrsw +attach pwrsw at obio with pwrsw_obio +file arch/landisk/dev/pwrsw_obio.c pwrsw_obio needs-flag + +#device led +#attach led at obio +#file arch/landisk/dev/led_obio.c led needs-flag diff --git a/sys/arch/landisk/include/_types.h b/sys/arch/landisk/include/_types.h new file mode 100644 index 00000000000..0bc412e33e0 --- /dev/null +++ b/sys/arch/landisk/include/_types.h @@ -0,0 +1 @@ +#include <sh/_types.h> diff --git a/sys/arch/landisk/include/asm.h b/sys/arch/landisk/include/asm.h new file mode 100644 index 00000000000..e917eac88cd --- /dev/null +++ b/sys/arch/landisk/include/asm.h @@ -0,0 +1 @@ +#include <sh/asm.h> diff --git a/sys/arch/landisk/include/autoconf.h b/sys/arch/landisk/include/autoconf.h new file mode 100644 index 00000000000..61c257978fb --- /dev/null +++ b/sys/arch/landisk/include/autoconf.h @@ -0,0 +1,52 @@ +/* $OpenBSD: autoconf.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: autoconf.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +struct mainbus_attach_args { + const char *ma_name; +}; + +struct confargs { + const char *ca_name; + u_int ca_node; + + int ca_nreg; + u_int *ca_reg; + + int ca_nintr; + int *ca_intr; + + u_long ca_baseaddr; +}; diff --git a/sys/arch/landisk/include/bootinfo.h b/sys/arch/landisk/include/bootinfo.h new file mode 100644 index 00000000000..c81709952ef --- /dev/null +++ b/sys/arch/landisk/include/bootinfo.h @@ -0,0 +1,70 @@ +/* $OpenBSD: bootinfo.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: bootinfo.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/* + * Copyright (c) 1997 + * Matthias Drochner. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +struct btinfo_common { + int len; + int type; +}; + +#define BTINFO_BOOTPATH 0 +#define BTINFO_BOOTDISK 1 +#define BTINFO_NETIF 2 + +struct btinfo_bootpath { + struct btinfo_common common; + char bootpath[80]; +}; + +struct btinfo_bootdisk { + struct btinfo_common common; + int labelsector; /* label valid if != -1 */ + struct { + uint16_t type, checksum; + char packname[16]; + } label; + int biosdev; + int partition; +}; + +struct btinfo_netif { + struct btinfo_common common; + char ifname[16]; + unsigned int tag; /* PCI, BIOS format */ +}; + +#define BOOTINFO_MAXSIZE 4096 + +struct bootinfo { + int nentries; + char info[BOOTINFO_MAXSIZE - sizeof(int)]; +}; + +#ifdef _KERNEL +void *lookup_bootinfo(int type); +#endif diff --git a/sys/arch/landisk/include/bus.h b/sys/arch/landisk/include/bus.h new file mode 100644 index 00000000000..b91feb43364 --- /dev/null +++ b/sys/arch/landisk/include/bus.h @@ -0,0 +1,646 @@ +/* $OpenBSD: bus.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: bus.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LANDISK_BUS_H_ +#define _LANDISK_BUS_H_ + +#include <sys/types.h> + +#ifdef _KERNEL +/* + * Turn on BUS_SPACE_DEBUG if the global DEBUG option is enabled. + */ +#if defined(DEBUG) && !defined(BUS_SPACE_DEBUG) +#define BUS_SPACE_DEBUG +#endif + +#ifdef BUS_SPACE_DEBUG +#include <sys/systm.h> /* for printf() prototype */ +/* + * Macros for checking the aligned-ness of pointers passed to bus + * space ops. Strict alignment is required by the SuperH architecture, + * and a trap will occur if unaligned access is performed. These + * may aid in the debugging of a broken device driver by displaying + * useful information about the problem. + */ +#define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \ + ((((u_long)(p)) & (sizeof(t)-1)) == 0) + +#define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \ +({ \ + if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \ + printf("%s 0x%lx not aligned to %lu bytes %s:%d\n", \ + d, (u_long)(p), (u_long)sizeof(t), __FILE__, __LINE__); \ + } \ + (void) 0; \ +}) +#else +#define __BUS_SPACE_ADDRESS_SANITY(p, t, d) (void) 0 +#endif /* BUS_SPACE_DEBUG */ +#endif /* _KERNEL */ + +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +typedef struct _bus_space *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +struct _bus_space { + /* cookie */ + void *bs_cookie; + + /* mapping/unmapping */ + int (*bs_map)(void *, bus_addr_t, bus_size_t, + int, bus_space_handle_t *); + void (*bs_unmap)(void *, bus_space_handle_t, + bus_size_t); + int (*bs_subregion)(void *, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + + /* allocation/deallocation */ + int (*bs_alloc)(void *, bus_addr_t, bus_addr_t, + bus_size_t, bus_size_t, bus_size_t, int, + bus_addr_t *, bus_space_handle_t *); + void (*bs_free)(void *, bus_space_handle_t, + bus_size_t); + + /* get kernel virtual address */ + void * (*bs_vaddr)(void *, bus_space_handle_t); + + /* read (single) */ + uint8_t (*bs_r_1)(void *, bus_space_handle_t, + bus_size_t); + uint16_t (*bs_r_2)(void *, bus_space_handle_t, + bus_size_t); + uint32_t (*bs_r_4)(void *, bus_space_handle_t, + bus_size_t); + uint64_t (*bs_r_8)(void *, bus_space_handle_t, + bus_size_t); + + /* read multiple */ + void (*bs_rm_1)(void *, bus_space_handle_t, + bus_size_t, uint8_t *, bus_size_t); + void (*bs_rm_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t *, bus_size_t); + void (*bs_rm_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t *, bus_size_t); + void (*bs_rm_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t *, bus_size_t); + + void (*bs_rrm_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t *, bus_size_t); + void (*bs_rrm_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t *, bus_size_t); + void (*bs_rrm_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t *, bus_size_t); + + /* read region */ + void (*bs_rr_1)(void *, bus_space_handle_t, + bus_size_t, uint8_t *, bus_size_t); + void (*bs_rr_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t *, bus_size_t); + void (*bs_rr_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t *, bus_size_t); + void (*bs_rr_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t *, bus_size_t); + + void (*bs_rrr_2)(void *, bus_space_handle_t, + bus_size_t, uint8_t *, bus_size_t); + void (*bs_rrr_4)(void *, bus_space_handle_t, + bus_size_t, uint8_t *, bus_size_t); + void (*bs_rrr_8)(void *, bus_space_handle_t, + bus_size_t, uint8_t *, bus_size_t); + + /* write (single) */ + void (*bs_w_1)(void *, bus_space_handle_t, + bus_size_t, uint8_t); + void (*bs_w_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t); + void (*bs_w_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t); + void (*bs_w_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t); + + /* write multiple */ + void (*bs_wm_1)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wm_2)(void *, bus_space_handle_t, + bus_size_t, const uint16_t *, bus_size_t); + void (*bs_wm_4)(void *, bus_space_handle_t, + bus_size_t, const uint32_t *, bus_size_t); + void (*bs_wm_8)(void *, bus_space_handle_t, + bus_size_t, const uint64_t *, bus_size_t); + + void (*bs_wrm_2)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wrm_4)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wrm_8)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + + /* write region */ + void (*bs_wr_1)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wr_2)(void *, bus_space_handle_t, + bus_size_t, const uint16_t *, bus_size_t); + void (*bs_wr_4)(void *, bus_space_handle_t, + bus_size_t, const uint32_t *, bus_size_t); + void (*bs_wr_8)(void *, bus_space_handle_t, + bus_size_t, const uint64_t *, bus_size_t); + + void (*bs_wrr_2)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wrr_4)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + void (*bs_wrr_8)(void *, bus_space_handle_t, + bus_size_t, const uint8_t *, bus_size_t); + + /* set multiple */ + void (*bs_sm_1)(void *, bus_space_handle_t, + bus_size_t, uint8_t, bus_size_t); + void (*bs_sm_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t, bus_size_t); + void (*bs_sm_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t, bus_size_t); + void (*bs_sm_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t, bus_size_t); + + /* set region */ + void (*bs_sr_1)(void *, bus_space_handle_t, + bus_size_t, uint8_t, bus_size_t); + void (*bs_sr_2)(void *, bus_space_handle_t, + bus_size_t, uint16_t, bus_size_t); + void (*bs_sr_4)(void *, bus_space_handle_t, + bus_size_t, uint32_t, bus_size_t); + void (*bs_sr_8)(void *, bus_space_handle_t, + bus_size_t, uint64_t, bus_size_t); + + /* copy */ + void (*bs_c_1)(void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_2)(void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_4)(void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_8)(void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); +}; + +#ifdef _KERNEL +/* + * Utility macros; INTERNAL USE ONLY. + */ +#define __bs_c(a,b) __CONCAT(a,b) +#define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size) + +#define __bs_rs(sz, tn, t, h, o) \ + (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ + (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)) + +#define __bs_ws(sz, tn, t, h, o, v) \ +do { \ + __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ + (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v); \ +} while (0) + +#define __bs_nonsingle(type, sz, tn, t, h, o, a, c) \ +do { \ + __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \ + __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ + (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c); \ +} while (0) + +#define __bs_set(type, sz, tn, t, h, o, v, c) \ +do { \ + __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ + (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c); \ +} while (0) + +#define __bs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \ +do { \ + __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \ + __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \ + (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt); \ +} while (0) + + +/* + * Mapping and unmapping operations. + */ +#define bus_space_map(t, a, s, f, hp) \ + (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp)) +#define bus_space_unmap(t, h, s) \ + (*(t)->bs_unmap)((t)->bs_cookie, (h), (s)) +#define bus_space_subregion(t, h, o, s, hp) \ + (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp)) + +#endif /* _KERNEL */ + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +#ifdef _KERNEL +/* + * Allocation and deallocation operations. + */ +#define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \ + (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \ + (f), (ap), (hp)) +#define bus_space_free(t, h, s) \ + (*(t)->bs_free)((t)->bs_cookie, (h), (s)) + +/* + * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. + */ +#define bus_space_vaddr(t, h) \ + (*(t)->bs_vaddr)((t)->bs_cookie, (h)) + +/* + * Bus barrier operations. The SH3 does not currently require + * barriers, but we must provide the flags to MI code. + */ +#define bus_space_barrier(t, h, o, l, f) \ + ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) + +#define BUS_SPACE_BARRIER_READ 0x01 +#define BUS_SPACE_BARRIER_WRITE 0x02 + + +/* + * Bus read (single) operations. + */ +#define bus_space_read_1(t, h, o) __bs_rs(1,uint8_t,(t),(h),(o)) +#define bus_space_read_2(t, h, o) __bs_rs(2,uint16_t,(t),(h),(o)) +#define bus_space_read_4(t, h, o) __bs_rs(4,uint32_t,(t),(h),(o)) +#define bus_space_read_8(t, h, o) __bs_rs(8,uint64_t,(t),(h),(o)) + + +/* + * Bus read multiple operations. + */ +#define bus_space_read_multi_1(t, h, o, a, c) \ + __bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_2(t, h, o, a, c) \ + __bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_4(t, h, o, a, c) \ + __bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_8(t, h, o, a, c) \ + __bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c)) + +#define bus_space_read_raw_multi_2(t, h, o, a, c) \ + __bs_nonsingle(rrm,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_read_raw_multi_4(t, h, o, a, c) \ + __bs_nonsingle(rrm,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_read_raw_multi_8(t, h, o, a, c) \ + __bs_nonsingle(rrm,8,uint64_t,(t),(h),(o),(a),(c)) + + +/* + * Bus read region operations. + */ +#define bus_space_read_region_1(t, h, o, a, c) \ + __bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c)) +#define bus_space_read_region_2(t, h, o, a, c) \ + __bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_read_region_4(t, h, o, a, c) \ + __bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_read_region_8(t, h, o, a, c) \ + __bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c)) + +#define bus_space_read_raw_region_2(t, h, o, a, c) \ + __bs_nonsingle(rrr,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_read_raw_region_4(t, h, o, a, c) \ + __bs_nonsingle(rrr,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_read_raw_region_8(t, h, o, a, c) \ + __bs_nonsingle(rrr,8,uint64_t,(t),(h),(o),(a),(c)) + + +/* + * Bus write (single) operations. + */ +#define bus_space_write_1(t, h, o, v) __bs_ws(1,uint8_t,(t),(h),(o),(v)) +#define bus_space_write_2(t, h, o, v) __bs_ws(2,uint16_t,(t),(h),(o),(v)) +#define bus_space_write_4(t, h, o, v) __bs_ws(4,uint32_t,(t),(h),(o),(v)) +#define bus_space_write_8(t, h, o, v) __bs_ws(8,uint64_t,(t),(h),(o),(v)) + + +/* + * Bus write multiple operations. + */ +#define bus_space_write_multi_1(t, h, o, a, c) \ + __bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_2(t, h, o, a, c) \ + __bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_4(t, h, o, a, c) \ + __bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_8(t, h, o, a, c) \ + __bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c)) + +#define bus_space_write_raw_multi_2(t, h, o, a, c) \ + __bs_nonsingle(wrm,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_write_raw_multi_4(t, h, o, a, c) \ + __bs_nonsingle(wrm,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_write_raw_multi_8(t, h, o, a, c) \ + __bs_nonsingle(wrm,8,uint64_t,(t),(h),(o),(a),(c)) + + +/* + * Bus write region operations. + */ +#define bus_space_write_region_1(t, h, o, a, c) \ + __bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c)) +#define bus_space_write_region_2(t, h, o, a, c) \ + __bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_write_region_4(t, h, o, a, c) \ + __bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_write_region_8(t, h, o, a, c) \ + __bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c)) + +#define bus_space_write_raw_region_2(t, h, o, a, c) \ + __bs_nonsingle(wrr,2,uint16_t,(t),(h),(o),(a),(c)) +#define bus_space_write_raw_region_4(t, h, o, a, c) \ + __bs_nonsingle(wrr,4,uint32_t,(t),(h),(o),(a),(c)) +#define bus_space_write_raw_region_8(t, h, o, a, c) \ + __bs_nonsingle(wrr,8,uint64_t,(t),(h),(o),(a),(c)) + + +/* + * Set multiple operations. + */ +#define bus_space_set_multi_1(t, h, o, v, c) \ + __bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_2(t, h, o, v, c) \ + __bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_4(t, h, o, v, c) \ + __bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_8(t, h, o, v, c) \ + __bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c)) + + +/* + * Set region operations. + */ +#define bus_space_set_region_1(t, h, o, v, c) \ + __bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c)) +#define bus_space_set_region_2(t, h, o, v, c) \ + __bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c)) +#define bus_space_set_region_4(t, h, o, v, c) \ + __bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c)) +#define bus_space_set_region_8(t, h, o, v, c) \ + __bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c)) + + +/* + * Copy region operations. + */ +#define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ + __bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ + __bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ + __bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c)) +#define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ + __bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c)) + +#endif /* _KERNEL */ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x004 /* map memory to not require sync */ +#define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */ +#define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x020 +#define BUS_DMA_BUS3 0x040 +#define BUS_DMA_BUS4 0x080 +#define BUS_DMA_READ 0x100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 +#define BUS_DMASYNC_POSTREAD 0x02 +#define BUS_DMASYNC_PREWRITE 0x04 +#define BUS_DMASYNC_POSTWRITE 0x08 + +typedef struct _bus_dma_tag *bus_dma_tag_t; +typedef struct _bus_dmamap *bus_dmamap_t; + +#define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct _bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + /* private section */ + bus_addr_t _ds_vaddr; /* virtual address */ +}; +typedef struct _bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct _bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, m, o, l, op) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct _bus_dmamap { + /* + * PRIVATE MEMBERS: not for use my machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#if defined(_LANDISK_BUS_DMA_PRIVATE) +int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, + struct proc *, int); +int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,int); +int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *, + int, bus_size_t, int); +void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, + int nsegs, int *rsegs, int flags); +void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs, + size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, size_t size); +paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); +#endif /* _LANDISK_BUS_DMA_PRIVATE */ + +#endif /* _LANDISK_BUS_H_ */ diff --git a/sys/arch/landisk/include/cdefs.h b/sys/arch/landisk/include/cdefs.h new file mode 100644 index 00000000000..ba3c9b1063b --- /dev/null +++ b/sys/arch/landisk/include/cdefs.h @@ -0,0 +1 @@ +#include <sh/cdefs.h> diff --git a/sys/arch/landisk/include/cpu.h b/sys/arch/landisk/include/cpu.h new file mode 100644 index 00000000000..44d1b43efe8 --- /dev/null +++ b/sys/arch/landisk/include/cpu.h @@ -0,0 +1,11 @@ +/* $OpenBSD: cpu.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: cpu.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +#ifndef _LANDISK_CPU_H_ +#define _LANDISK_CPU_H_ + +void machine_reset(void); + +#include <sh/cpu.h> + +#endif /* _LANDISK_CPU_H_ */ diff --git a/sys/arch/landisk/include/cputypes.h b/sys/arch/landisk/include/cputypes.h new file mode 100644 index 00000000000..c1c8493d256 --- /dev/null +++ b/sys/arch/landisk/include/cputypes.h @@ -0,0 +1 @@ +#include <sh/cputypes.h> diff --git a/sys/arch/landisk/include/db_machdep.h b/sys/arch/landisk/include/db_machdep.h new file mode 100644 index 00000000000..9250b90be81 --- /dev/null +++ b/sys/arch/landisk/include/db_machdep.h @@ -0,0 +1 @@ +#include <sh/db_machdep.h> diff --git a/sys/arch/landisk/include/disklabel.h b/sys/arch/landisk/include/disklabel.h new file mode 100644 index 00000000000..4d7cc146698 --- /dev/null +++ b/sys/arch/landisk/include/disklabel.h @@ -0,0 +1 @@ +#include <sh/disklabel.h> diff --git a/sys/arch/landisk/include/endian.h b/sys/arch/landisk/include/endian.h new file mode 100644 index 00000000000..ca58dabddbd --- /dev/null +++ b/sys/arch/landisk/include/endian.h @@ -0,0 +1 @@ +#include <sh/endian.h> diff --git a/sys/arch/landisk/include/exec.h b/sys/arch/landisk/include/exec.h new file mode 100644 index 00000000000..59f701743a2 --- /dev/null +++ b/sys/arch/landisk/include/exec.h @@ -0,0 +1 @@ +#include <sh/exec.h> diff --git a/sys/arch/landisk/include/float.h b/sys/arch/landisk/include/float.h new file mode 100644 index 00000000000..4d4d864b4ad --- /dev/null +++ b/sys/arch/landisk/include/float.h @@ -0,0 +1 @@ +#include <sh/float.h> diff --git a/sys/arch/landisk/include/frame.h b/sys/arch/landisk/include/frame.h new file mode 100644 index 00000000000..cc4d91e9491 --- /dev/null +++ b/sys/arch/landisk/include/frame.h @@ -0,0 +1 @@ +#include <sh/frame.h> diff --git a/sys/arch/landisk/include/ieee.h b/sys/arch/landisk/include/ieee.h new file mode 100644 index 00000000000..7d03cf8075f --- /dev/null +++ b/sys/arch/landisk/include/ieee.h @@ -0,0 +1 @@ +#include <sh/ieee.h> diff --git a/sys/arch/landisk/include/ieeefp.h b/sys/arch/landisk/include/ieeefp.h new file mode 100644 index 00000000000..8aad0de9b09 --- /dev/null +++ b/sys/arch/landisk/include/ieeefp.h @@ -0,0 +1 @@ +#include <sh/ieeefp.h> diff --git a/sys/arch/landisk/include/internal_types.h b/sys/arch/landisk/include/internal_types.h new file mode 100644 index 00000000000..97f223191d0 --- /dev/null +++ b/sys/arch/landisk/include/internal_types.h @@ -0,0 +1 @@ +#include <sh/internal_types.h> diff --git a/sys/arch/landisk/include/intr.h b/sys/arch/landisk/include/intr.h new file mode 100644 index 00000000000..6ddc15c4ad0 --- /dev/null +++ b/sys/arch/landisk/include/intr.h @@ -0,0 +1,79 @@ +/* $OpenBSD: intr.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: intr.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LANDISK_INTR_H_ +#define _LANDISK_INTR_H_ + +#include <sh/intr.h> + +/* Number of interrupt source */ +#define _INTR_N 16 + +/* Interrupt priority levels */ +#define IPL_BIO 10 /* block I/O */ +#define IPL_NET 11 /* network */ +#define IPL_TTY 12 /* terminal */ +#define IPL_SERIAL 13 /* serial */ +#define IPL_CLOCK 14 /* clock */ +#define IPL_HIGH 15 /* everything */ + +#define splsoftclock() _cpu_intr_raise(IPL_SOFTCLOCK << 4) +#define splsoftnet() _cpu_intr_raise(IPL_SOFTNET << 4) +#define splsoftserial() _cpu_intr_raise(IPL_SOFTSERIAL << 4) +#define splbio() _cpu_intr_raise(IPL_BIO << 4) +#define splnet() _cpu_intr_raise(IPL_NET << 4) +#define spltty() _cpu_intr_raise(IPL_TTY << 4) +#define splvm() spltty() +#define splserial() _cpu_intr_raise(IPL_SERIAL << 4) +#define splclock() _cpu_intr_raise(IPL_CLOCK << 4) +#define splstatclock() splclock() +#define splsched() splclock() +#define splhigh() _cpu_intr_raise(IPL_HIGH << 4) +#define spllock() splhigh() + +#define spl0() _cpu_intr_resume(IPL_NONE << 4) +#define splx(x) _cpu_intr_resume(x) + +#define splassert(wantipl) do { /* nothing yet */ } while (0) + +void intr_init(void); +void *extintr_establish(int, int, int (*)(void *), void *, const char *); +void extintr_disestablish(void *ih); +void extintr_enable(void *ih); +void extintr_disable(void *ih); +void extintr_disable_by_num(int irq); + +#endif /* !_LANDISK_INTR_H_ */ diff --git a/sys/arch/landisk/include/limits.h b/sys/arch/landisk/include/limits.h new file mode 100644 index 00000000000..d2253f0ac2b --- /dev/null +++ b/sys/arch/landisk/include/limits.h @@ -0,0 +1 @@ +#include <sh/limits.h> diff --git a/sys/arch/landisk/include/lock.h b/sys/arch/landisk/include/lock.h new file mode 100644 index 00000000000..1434c39c745 --- /dev/null +++ b/sys/arch/landisk/include/lock.h @@ -0,0 +1 @@ +#include <sh/lock.h> diff --git a/sys/arch/landisk/include/param.h b/sys/arch/landisk/include/param.h new file mode 100644 index 00000000000..3801db99fac --- /dev/null +++ b/sys/arch/landisk/include/param.h @@ -0,0 +1,58 @@ +/* $OpenBSD: param.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: param.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)param.h 5.8 (Berkeley) 6/28/91 + */ + +/* + * Machine dependent constants for landisk + */ + +#ifndef _LANDISK_PARAM_H_ +#define _LANDISK_PARAM_H_ + +#include <sh/param.h> + +#define _MACHINE landisk +#define MACHINE "landisk" + +/* + * Physical addresses of on-board ROM and RAM + */ +#define IOM_ROM_BEGIN 0x00000000 +#define IOM_ROM_SIZE 0x00080000 /* 512KB */ +#define IOM_RAM_BEGIN 0x0c000000 +#define IOM_RAM_SIZE 0x04000000 /* 64MB */ + +#endif /* _LANDISK_PARAM_H_ */ diff --git a/sys/arch/landisk/include/pcb.h b/sys/arch/landisk/include/pcb.h new file mode 100644 index 00000000000..e22d11fe8da --- /dev/null +++ b/sys/arch/landisk/include/pcb.h @@ -0,0 +1 @@ +#include <sh/pcb.h> diff --git a/sys/arch/landisk/include/pci_machdep.h b/sys/arch/landisk/include/pci_machdep.h new file mode 100644 index 00000000000..883a7d526c3 --- /dev/null +++ b/sys/arch/landisk/include/pci_machdep.h @@ -0,0 +1,81 @@ +/* $OpenBSD: pci_machdep.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/* + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1994 Charles M. Hannum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles M. Hannum. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Types provided to machine-independent PCI code + */ +typedef void *pci_chipset_tag_t; +typedef u_int pcitag_t; +typedef u_int pci_intr_handle_t; + +#include <sh/dev/shpcicvar.h> + +/* + * Forward declarations. + */ +struct pci_attach_args; + +/* + * Functions provided to machine-independent PCI code. + */ +void landisk_pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int landisk_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +const char *landisk_pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *landisk_pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, int, + int (*)(void *), void *, const char *); +void landisk_pci_intr_disestablish(pci_chipset_tag_t, void *); +void landisk_pci_conf_interrupt(void *v, int bus, int dev, int pin, + int swiz, int *iline); + +#define pci_bus_maxdevs(v, busno) \ + shpcic_bus_maxdevs(v, busno) +#define pci_make_tag(v, bus, dev, func) \ + shpcic_make_tag(v, bus, dev, func) +#define pci_decompose_tag(v, tag, bp, dp, fp) \ + shpcic_decompose_tag(v, tag, bp, dp, fp) +#define pci_conf_read(v, tag, reg) \ + shpcic_conf_read(v, tag, reg) +#define pci_conf_write(v, tag, reg, data) \ + shpcic_conf_write(v, tag, reg, data) + +#define pci_attach_hook(pa, self, pba) \ + landisk_pci_attach_hook(pa, self, pba) +#define pci_intr_map(pa, ihp) \ + landisk_pci_intr_map(pa, ihp) +#define pci_intr_string(v, ih) \ + landisk_pci_intr_string(v, ih) +#define pci_intr_establish(v, ih, level, ih_fun, ih_arg, ih_name) \ + landisk_pci_intr_establish(v, ih, level, ih_fun, ih_arg, ih_name) +#define pci_intr_disestablish(v, cookie) \ + landisk_pci_intr_disestablish(v, cookie) diff --git a/sys/arch/landisk/include/pmap.h b/sys/arch/landisk/include/pmap.h new file mode 100644 index 00000000000..beb43a7ed71 --- /dev/null +++ b/sys/arch/landisk/include/pmap.h @@ -0,0 +1 @@ +#include <sh/pmap.h> diff --git a/sys/arch/landisk/include/proc.h b/sys/arch/landisk/include/proc.h new file mode 100644 index 00000000000..f213a27ca21 --- /dev/null +++ b/sys/arch/landisk/include/proc.h @@ -0,0 +1 @@ +#include <sh/proc.h> diff --git a/sys/arch/landisk/include/profile.h b/sys/arch/landisk/include/profile.h new file mode 100644 index 00000000000..2e4937362b4 --- /dev/null +++ b/sys/arch/landisk/include/profile.h @@ -0,0 +1 @@ +#include <sh/profile.h> diff --git a/sys/arch/landisk/include/psl.h b/sys/arch/landisk/include/psl.h new file mode 100644 index 00000000000..91af96f74a7 --- /dev/null +++ b/sys/arch/landisk/include/psl.h @@ -0,0 +1 @@ +#include <sh/psl.h> diff --git a/sys/arch/landisk/include/pte.h b/sys/arch/landisk/include/pte.h new file mode 100644 index 00000000000..9aca69f3a70 --- /dev/null +++ b/sys/arch/landisk/include/pte.h @@ -0,0 +1 @@ +#include <sh/pte.h> diff --git a/sys/arch/landisk/include/ptrace.h b/sys/arch/landisk/include/ptrace.h new file mode 100644 index 00000000000..57716b16969 --- /dev/null +++ b/sys/arch/landisk/include/ptrace.h @@ -0,0 +1 @@ +#include <sh/ptrace.h> diff --git a/sys/arch/landisk/include/reg.h b/sys/arch/landisk/include/reg.h new file mode 100644 index 00000000000..e5ba4695b4d --- /dev/null +++ b/sys/arch/landisk/include/reg.h @@ -0,0 +1 @@ +#include <sh/reg.h> diff --git a/sys/arch/landisk/include/setjmp.h b/sys/arch/landisk/include/setjmp.h new file mode 100644 index 00000000000..11937acb717 --- /dev/null +++ b/sys/arch/landisk/include/setjmp.h @@ -0,0 +1 @@ +#include <sh/setjmp.h> diff --git a/sys/arch/landisk/include/signal.h b/sys/arch/landisk/include/signal.h new file mode 100644 index 00000000000..8d268ae5cd5 --- /dev/null +++ b/sys/arch/landisk/include/signal.h @@ -0,0 +1 @@ +#include <sh/signal.h> diff --git a/sys/arch/landisk/include/spinlock.h b/sys/arch/landisk/include/spinlock.h new file mode 100644 index 00000000000..ef21c8cb083 --- /dev/null +++ b/sys/arch/landisk/include/spinlock.h @@ -0,0 +1 @@ +#include <sh/spinlock.h> diff --git a/sys/arch/landisk/include/stdarg.h b/sys/arch/landisk/include/stdarg.h new file mode 100644 index 00000000000..176dcb1658c --- /dev/null +++ b/sys/arch/landisk/include/stdarg.h @@ -0,0 +1 @@ +#include <sh/stdarg.h> diff --git a/sys/arch/landisk/include/trap.h b/sys/arch/landisk/include/trap.h new file mode 100644 index 00000000000..86fec654f65 --- /dev/null +++ b/sys/arch/landisk/include/trap.h @@ -0,0 +1 @@ +#include <sh/trap.h> diff --git a/sys/arch/landisk/include/types.h b/sys/arch/landisk/include/types.h new file mode 100644 index 00000000000..97f7a515a87 --- /dev/null +++ b/sys/arch/landisk/include/types.h @@ -0,0 +1 @@ +#include <sh/types.h> diff --git a/sys/arch/landisk/include/varargs.h b/sys/arch/landisk/include/varargs.h new file mode 100644 index 00000000000..1d4c2a64d79 --- /dev/null +++ b/sys/arch/landisk/include/varargs.h @@ -0,0 +1 @@ +#include <sh/varargs.h> diff --git a/sys/arch/landisk/include/vmparam.h b/sys/arch/landisk/include/vmparam.h new file mode 100644 index 00000000000..21449a7e0d5 --- /dev/null +++ b/sys/arch/landisk/include/vmparam.h @@ -0,0 +1,16 @@ +/* $OpenBSD: vmparam.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +#ifndef _LANDISK_VMPARAM_H_ +#define _LANDISK_VMPARAM_H_ + +#include <sh/vmparam.h> + +#define VM_PHYSSEG_MAX 1 +#define VM_PHYSSEG_NOADD +#define VM_PHYSSEG_STRAT VM_PSTRAT_RANDOM + +#define VM_NFREELIST 1 +#define VM_FREELIST_DEFAULT 0 + +#endif /* _LANDISK_VMPARAM_H_ */ diff --git a/sys/arch/landisk/landisk/bus_dma.c b/sys/arch/landisk/landisk/bus_dma.c new file mode 100644 index 00000000000..e7691bf5917 --- /dev/null +++ b/sys/arch/landisk/landisk/bus_dma.c @@ -0,0 +1,694 @@ +/* $OpenBSD: bus_dma.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: bus_dma.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/* + * Copyright (c) 2005 NONAKA Kimihiro + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/device.h> +#include <sys/malloc.h> +#include <sys/mbuf.h> + +#include <uvm/uvm_extern.h> + +#include <sh/cache.h> + +#include <machine/autoconf.h> +#define _LANDISK_BUS_DMA_PRIVATE +#include <machine/bus.h> + +#if defined(DEBUG) && defined(BUSDMA_DEBUG) +#define DPRINTF(a) printf a +#else +#define DPRINTF(a) +#endif + +struct _bus_dma_tag landisk_bus_dma = { + ._cookie = NULL, + + ._dmamap_create = _bus_dmamap_create, + ._dmamap_destroy = _bus_dmamap_destroy, + ._dmamap_load = _bus_dmamap_load, + ._dmamap_load_mbuf = _bus_dmamap_load_mbuf, + ._dmamap_load_uio = _bus_dmamap_load_uio, + ._dmamap_load_raw = _bus_dmamap_load_raw, + ._dmamap_unload = _bus_dmamap_unload, + ._dmamap_sync = _bus_dmamap_sync, + + ._dmamem_alloc = _bus_dmamem_alloc, + ._dmamem_free = _bus_dmamem_free, + ._dmamem_map = _bus_dmamem_map, + ._dmamem_unmap = _bus_dmamem_unmap, + ._dmamem_mmap = _bus_dmamem_mmap, +}; + +/* + * Create a DMA map. + */ +int +_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, + bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp) +{ + bus_dmamap_t map; + void *mapstore; + size_t mapsize; + int error; + + DPRINTF(("bus_dmamap_create: t = %p, size = %ld, nsegments = %d, maxsegsz = %ld, boundary = %ld, flags = %x\n", t, size, nsegments, maxsegsz, boundary, flags)); + + /* + * Allocate and initialize the DMA map. The end of the map + * is a variable-sized array of segments, so we allocate enough + * room for them in one shot. + * + * Note we don't preserve the WAITOK or NOWAIT flags. Preservation + * of ALLOCNOW notifies others that we've reserved these resources, + * and they are not to be freed. + * + * The bus_dmamap_t includes one bus_dma_segment_t, hence + * the (nsegments - 1). + */ + error = 0; + mapsize = sizeof(struct _bus_dmamap) + + (sizeof(bus_dma_segment_t) * (nsegments - 1)); + if ((mapstore = malloc(mapsize, M_DEVBUF, + (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) + return (ENOMEM); + + DPRINTF(("bus_dmamap_create: dmamp = %p\n", mapstore)); + + memset(mapstore, 0, mapsize); + map = (bus_dmamap_t)mapstore; + map->_dm_size = size; + map->_dm_segcnt = nsegments; + map->_dm_maxsegsz = maxsegsz; + map->_dm_boundary = boundary; + map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT); + + map->dm_mapsize = 0; /* no valid mappings */ + map->dm_nsegs = 0; + + *dmamp = map; + + return (0); +} + +/* + * Destroy a DMA map. + */ +void +_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map) +{ + + DPRINTF(("bus_dmamap_destroy: t = %p, map = %p\n", t, map)); + + free(map, M_DEVBUF); +} + +static inline int +_bus_dmamap_load_paddr(bus_dma_tag_t t, bus_dmamap_t map, + paddr_t paddr, vaddr_t vaddr, int size, int *segp, paddr_t *lastaddrp, + int first) +{ + bus_dma_segment_t * const segs = map->dm_segs; + bus_addr_t bmask = ~(map->_dm_boundary - 1); + bus_addr_t lastaddr; + int nseg; + int sgsize; + + nseg = *segp; + lastaddr = *lastaddrp; + + DPRINTF(("_bus_dmamap_load_paddr: t = %p, map = %p, paddr = 0x%08lx, vaddr = 0x%08lx, size = %d\n", t, map, paddr, vaddr, size)); + DPRINTF(("_bus_dmamap_load_paddr: nseg = %d, bmask = 0x%08lx, lastaddr = 0x%08lx\n", nseg, bmask, lastaddr)); + + do { + sgsize = size; + + /* + * Make sure we don't cross any boundaries. + */ + if (map->_dm_boundary > 0) { + bus_addr_t baddr; /* next boundary address */ + + baddr = (paddr + map->_dm_boundary) & bmask; + if (sgsize > (baddr - paddr)) + sgsize = (baddr - paddr); + } + + DPRINTF(("_bus_dmamap_load_paddr: sgsize = %d\n", sgsize)); + + /* + * Insert chunk into a segment, coalescing with + * previous segment if possible. + */ + if (first) { + /* first segment */ + DPRINTF(("_bus_dmamap_load_paddr: first\n")); + segs[nseg].ds_addr = SH3_PHYS_TO_P2SEG(paddr); + segs[nseg].ds_len = sgsize; + segs[nseg]._ds_vaddr = vaddr; + first = 0; + } else { + if ((paddr == lastaddr) + && (segs[nseg].ds_len + sgsize <= map->_dm_maxsegsz) + && (map->_dm_boundary == 0 || + (segs[nseg].ds_addr & bmask) == (paddr & bmask))) { + /* coalesce */ + DPRINTF(("_bus_dmamap_load_paddr: coalesce\n")); + segs[nseg].ds_len += sgsize; + } else { + if (++nseg >= map->_dm_segcnt) { + break; + } + /* new segment */ + DPRINTF(("_bus_dmamap_load_paddr: new\n")); + segs[nseg].ds_addr = SH3_PHYS_TO_P2SEG(paddr); + segs[nseg].ds_len = sgsize; + segs[nseg]._ds_vaddr = vaddr; + } + } + + lastaddr = paddr + sgsize; + paddr += sgsize; + vaddr += sgsize; + size -= sgsize; + DPRINTF(("_bus_dmamap_load_paddr: lastaddr = 0x%08lx, paddr = 0x%08lx, vaddr = 0x%08lx, size = %d\n", lastaddr, paddr, vaddr, size)); + } while (size > 0); + + DPRINTF(("_bus_dmamap_load_paddr: nseg = %d\n", nseg)); + + *segp = nseg; + *lastaddrp = lastaddr; + + /* + * Did we fit? + */ + if (size != 0) { + /* + * If there is a chained window, we will automatically + * fall back to it. + */ + return (EFBIG); /* XXX better return value here? */ + } + + return (0); +} + +static inline int +_bus_bus_dmamap_load_buffer(bus_dma_tag_t t, bus_dmamap_t map, void *buf, + bus_size_t buflen, struct proc *p, int flags, int *segp) +{ + bus_size_t sgsize; + bus_addr_t curaddr; + bus_size_t len; + paddr_t lastaddr; + vaddr_t vaddr = (vaddr_t)buf; + pmap_t pmap; + int first; + int error; + + DPRINTF(("_bus_dmamap_load_buffer: t = %p, map = %p, buf = %p, buflen = %ld, p = %p, flags = %x\n", t, map, buf, buflen, p, flags)); + + if (p != NULL) + pmap = p->p_vmspace->vm_map.pmap; + else + pmap = pmap_kernel(); + + *segp = 0; + first = 1; + len = buflen; + lastaddr = 0; /* XXX: uwe: gag gcc4, but this is WRONG!!! */ + while (len > 0) { + /* + * Get the physical address for this segment. + */ + (void)pmap_extract(pmap, vaddr, &curaddr); + + /* + * Compute the segment size, and adjust counts. + */ + sgsize = PAGE_SIZE - ((u_long)vaddr & PGOFSET); + if (len < sgsize) + sgsize = len; + + error = _bus_dmamap_load_paddr(t, map, curaddr, vaddr, sgsize, + segp, &lastaddr, first); + if (error) + return (error); + + vaddr += sgsize; + len -= sgsize; + first = 0; + } + + return (0); +} + +/* + * Load a DMA map with a linear buffer. + */ +int +_bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf, + bus_size_t buflen, struct proc *p, int flags) +{ + bus_addr_t addr = (bus_addr_t)buf; + paddr_t lastaddr; + int seg; + int first; + int error; + + DPRINTF(("bus_dmamap_load: t = %p, map = %p, buf = %p, buflen = %ld, p = %p, flags = %x\n", t, map, buf, buflen, p, flags)); + + /* + * Make sure on error condition we return "no valid mappings." + */ + map->dm_mapsize = 0; + map->dm_nsegs = 0; + + if (buflen > map->_dm_size) + return (EINVAL); + + lastaddr = 0; /* XXX: uwe: gag gcc4, but this is WRONG!!! */ + + if ((addr >= SH3_P1SEG_BASE) && (addr + buflen <= SH3_P2SEG_END)) { + bus_addr_t curaddr; + bus_size_t sgsize; + bus_size_t len = buflen; + + DPRINTF(("bus_dmamap_load: P[12]SEG (0x%08lx)\n", addr)); + + seg = 0; + first = 1; + while (len > 0) { + curaddr = SH3_P1SEG_TO_PHYS(addr); + + sgsize = PAGE_SIZE - ((u_long)addr & PGOFSET); + if (len < sgsize) + sgsize = len; + + error = _bus_dmamap_load_paddr(t, map, curaddr, addr, + sgsize, &seg, &lastaddr, first); + if (error) + return (error); + + addr += sgsize; + len -= sgsize; + first = 0; + } + + map->dm_nsegs = seg + 1; + map->dm_mapsize = buflen; + return (0); + } + + error = _bus_bus_dmamap_load_buffer(t, map, buf, buflen, p, flags, + &seg); + if (error == 0) { + map->dm_nsegs = seg + 1; + map->dm_mapsize = buflen; + return (0); + } + + return (error); +} + +/* + * Like _bus_dmamap_load(), but for mbufs. + */ +int +_bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t map, struct mbuf *m0, + int flags) +{ + struct mbuf *m; + paddr_t lastaddr; + int seg; + int first; + int error; + + DPRINTF(("bus_dmamap_load_mbuf: t = %p, map = %p, m0 = %p, flags = %x\n", t, map, m0, flags)); + + /* + * Make sure on error condition we return "no valid mappings." + */ + map->dm_nsegs = 0; + map->dm_mapsize = 0; + +#ifdef DIAGNOSTIC + if ((m0->m_flags & M_PKTHDR) == 0) + panic("_bus_dmamap_load_mbuf: no packet header"); +#endif + + if (m0->m_pkthdr.len > map->_dm_size) + return (EINVAL); + + seg = 0; + first = 1; + error = 0; + lastaddr = 0; /* XXX: uwe: gag gcc4, but this is WRONG!!! */ + for (m = m0; m != NULL && error == 0; m = m->m_next) { + paddr_t paddr; + vaddr_t vaddr; + int size; + + if (m->m_len == 0) + continue; + + vaddr = (vaddr_t)(m->m_data); + paddr = (paddr_t)(SH3_P1SEG_TO_PHYS(vaddr)); + size = m->m_len; + error = _bus_dmamap_load_paddr(t, map, paddr, vaddr, size, + &seg, &lastaddr, first); + first = 0; + } + + if (error == 0) { + map->dm_nsegs = seg + 1; + map->dm_mapsize = m0->m_pkthdr.len; + return (0); + } + + return (error); +} + +/* + * Like _bus_dmamap_load(), but for uios. + */ +int +_bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map, struct uio *uio, + int flags) +{ + + panic("_bus_dmamap_load_uio: not implemented"); +} + +/* + * Like _bus_dmamap_load(), but for raw memory allocated with + * bus_dmamem_alloc(). + */ +int +_bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, + bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags) +{ + + panic("_bus_dmamap_load_raw: not implemented"); +} + +/* + * Unload a DMA map. + */ +void +_bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map) +{ + + DPRINTF(("bus_dmamap_unload: t = %p, map = %p\n", t, map)); + + map->dm_nsegs = 0; + map->dm_mapsize = 0; +} + +/* + * Synchronize a DMA map. + */ +void +_bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset, + bus_size_t len, int ops) +{ + bus_size_t minlen; + bus_addr_t addr, naddr; + int i; + + DPRINTF(("bus_dmamap_sync: t = %p, map = %p, offset = %ld, len = %ld, ops = %x\n", t, map, offset, len, ops)); + + /* + * Mixing PRE and POST operations is not allowed. + */ + if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 && + (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0) + panic("_bus_dmamap_sync: mix PRE and POST"); + +#ifdef DIAGNOSTIC + if (offset >= map->dm_mapsize) + panic("_bus_dmamap_sync: bad offset"); + if ((offset + len) > map->dm_mapsize) + panic("_bus_dmamap_sync: bad length"); +#endif + + if (!sh_cache_enable_dcache) { + /* Nothing to do */ + DPRINTF(("bus_dmamap_sync: disabled D-Cache\n")); + return; + } + + for (i = 0; i < map->dm_nsegs && len != 0; i++) { + /* Find the beginning segment. */ + if (offset >= map->dm_segs[i].ds_len) { + offset -= map->dm_segs[i].ds_len; + continue; + } + + /* + * Now at the first segment to sync; nail + * each segment until we have exhausted the + * length. + */ + minlen = len < map->dm_segs[i].ds_len - offset ? + len : map->dm_segs[i].ds_len - offset; + + addr = map->dm_segs[i]._ds_vaddr; + naddr = addr + offset; + + if ((naddr >= SH3_P2SEG_BASE) + && (naddr + minlen <= SH3_P2SEG_END)) { + DPRINTF(("bus_dmamap_sync: P2SEG (0x%08lx)\n", naddr)); + offset = 0; + len -= minlen; + continue; + } + + DPRINTF(("bus_dmamap_sync: flushing segment %d " + "(0x%lx+%lx, 0x%lx+0x%lx) (remain = %ld)\n", + i, addr, offset, addr, offset + minlen - 1, len)); + + switch (ops) { + case BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE: + sh_dcache_wbinv_range(naddr, minlen); + break; + + case BUS_DMASYNC_PREREAD: + if (((naddr | minlen) & (~(sh_cache_line_size - 1))) == 0) { + sh_dcache_inv_range(naddr, minlen); + } else { + sh_dcache_wbinv_range(naddr, minlen); + } + break; + + case BUS_DMASYNC_PREWRITE: + if (SH_HAS_WRITEBACK_CACHE) { + sh_dcache_wb_range(naddr, minlen); + } + break; + } + offset = 0; + len -= minlen; + } +} + +/* + * Allocate memory safe for DMA. + */ +int +_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, + bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, + int flags) +{ + extern paddr_t avail_start, avail_end; /* from pmap.c */ + struct pglist mlist; + paddr_t curaddr, lastaddr; + struct vm_page *m; + int curseg, error; + + DPRINTF(("bus_dmamem_alloc: t = %p, size = %ld, alignment = %ld, boundary = %ld, segs = %p, nsegs = %d, rsegs = %p, flags = %x\n", t, size, alignment, boundary, segs, nsegs, rsegs, flags)); + DPRINTF(("bus_dmamem_alloc: avail_start = 0x%08lx, avail_end = 0x%08lx\n", avail_start, avail_end)); + + /* Always round the size. */ + size = round_page(size); + + /* + * Allocate the pages from the VM system. + */ + error = uvm_pglistalloc(size, avail_start, avail_end - PAGE_SIZE, + alignment, boundary, &mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); + if (error) + return (error); + + /* + * Compute the location, size, and number of segments actually + * returned by the VM code. + */ + m = mlist.tqh_first; + curseg = 0; + lastaddr = segs[curseg].ds_addr = VM_PAGE_TO_PHYS(m); + segs[curseg].ds_len = PAGE_SIZE; + + DPRINTF(("bus_dmamem_alloc: m = %p, lastaddr = 0x%08lx\n",m,lastaddr)); + + while ((m = TAILQ_NEXT(m, pageq)) != NULL) { + curaddr = VM_PAGE_TO_PHYS(m); + DPRINTF(("bus_dmamem_alloc: m = %p, curaddr = 0x%08lx, lastaddr = 0x%08lx\n", m, curaddr, lastaddr)); + if (curaddr == (lastaddr + PAGE_SIZE)) { + segs[curseg].ds_len += PAGE_SIZE; + } else { + DPRINTF(("bus_dmamem_alloc: new segment\n")); + curseg++; + segs[curseg].ds_addr = curaddr; + segs[curseg].ds_len = PAGE_SIZE; + } + lastaddr = curaddr; + } + + *rsegs = curseg + 1; + + DPRINTF(("bus_dmamem_alloc: curseg = %d, *rsegs = %d\n",curseg,*rsegs)); + + return (0); +} + +/* + * Common function for freeing DMA-safe memory. May be called by + * bus-specific DMA memory free functions. + */ +void +_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) +{ + struct vm_page *m; + bus_addr_t addr; + struct pglist mlist; + int curseg; + + DPRINTF(("bus_dmamem_free: t = %p, segs = %p, nsegs = %d\n", t, segs, nsegs)); + + /* + * Build a list of pages to free back to the VM system. + */ + TAILQ_INIT(&mlist); + for (curseg = 0; curseg < nsegs; curseg++) { + DPRINTF(("bus_dmamem_free: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n", curseg, segs[curseg].ds_addr, segs[curseg].ds_len)); + for (addr = segs[curseg].ds_addr; + addr < (segs[curseg].ds_addr + segs[curseg].ds_len); + addr += PAGE_SIZE) { + m = PHYS_TO_VM_PAGE(addr); + DPRINTF(("bus_dmamem_free: m = %p\n", m)); + TAILQ_INSERT_TAIL(&mlist, m, pageq); + } + } + + uvm_pglistfree(&mlist); +} + + +int +_bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, + size_t size, caddr_t *kvap, int flags) +{ + vaddr_t va; + bus_addr_t addr; + int curseg; + + DPRINTF(("bus_dmamem_map: t = %p, segs = %p, nsegs = %d, size = %d, kvap = %p, flags = %x\n", t, segs, nsegs, size, kvap, flags)); + + /* + * If we're only mapping 1 segment, use P2SEG, to avoid + * TLB thrashing. + */ + if (nsegs == 1) { + if (flags & BUS_DMA_COHERENT) { + *kvap = (caddr_t)SH3_PHYS_TO_P2SEG(segs[0].ds_addr); + } else { + *kvap = (caddr_t)SH3_PHYS_TO_P1SEG(segs[0].ds_addr); + } + DPRINTF(("bus_dmamem_map: addr = 0x%08lx, kva = %p\n", segs[0].ds_addr, *kvap)); + return 0; + } + + /* Always round the size. */ + size = round_page(size); + + va = uvm_km_valloc(kernel_map, size); + if (va == 0) + return (ENOMEM); + + *kvap = (caddr_t)va; + for (curseg = 0; curseg < nsegs; curseg++) { + DPRINTF(("bus_dmamem_map: segs[%d]: ds_addr = 0x%08lx, ds_len = %ld\n", curseg, segs[curseg].ds_addr, segs[curseg].ds_len)); + for (addr = segs[curseg].ds_addr; + addr < segs[curseg].ds_addr + segs[curseg].ds_len; + addr += PAGE_SIZE, va += PAGE_SIZE, size -= PAGE_SIZE) { + if (size == 0) + panic("_bus_dmamem_map: size botch"); + pmap_kenter_pa(va, addr, + VM_PROT_READ | VM_PROT_WRITE); + } + } + pmap_update(pmap_kernel()); + + return (0); +} + +void +_bus_dmamem_unmap(bus_dma_tag_t t, caddr_t kva, size_t size) +{ + + DPRINTF(("bus_dmamem_unmap: t = %p, kva = %p, size = %d\n", t, kva, size)); + +#ifdef DIAGNOSTIC + if ((u_long)kva & PAGE_MASK) + panic("_bus_dmamem_unmap"); +#endif + + /* + * Nothing to do if we mapped it with P[12]SEG. + */ + if ((kva >= (caddr_t)SH3_P1SEG_BASE) + && (kva <= (caddr_t)SH3_P2SEG_END)) { + return; + } + + size = round_page(size); + pmap_kremove((vaddr_t)kva, size); + pmap_update(pmap_kernel()); + uvm_km_free(kernel_map, (vaddr_t)kva, size); +} + +paddr_t +_bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, + off_t off, int prot, int flags) +{ + + /* Not implemented. */ + return (paddr_t)(-1); +} diff --git a/sys/arch/landisk/landisk/consinit.c b/sys/arch/landisk/landisk/consinit.c new file mode 100644 index 00000000000..64d6d712086 --- /dev/null +++ b/sys/arch/landisk/landisk/consinit.c @@ -0,0 +1,68 @@ +/* $OpenBSD: consinit.c,v 1.1.1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: consinit.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/* + * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles Hannum. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/conf.h> +#include <sys/systm.h> + +#include <dev/cons.h> + +#include "scif.h" + +#define scifcnpollc nullcnpollc +cons_decl(scif); + +struct consdev constab[] = { +#if NSCIF > 0 + cons_init(scif), +#endif + { 0 }, +}; + +/* + * consinit: + * initialize the system console. + * + * XXX - shouldn't deal with this initted thing, but then, + * it shouldn't be called from init386 either. + */ +void +consinit(void) +{ + static int initted; + + if (initted) + return; + initted = 1; + + cninit(); +} diff --git a/sys/arch/landisk/landisk/disksubr.c b/sys/arch/landisk/landisk/disksubr.c new file mode 100644 index 00000000000..23bb73176e9 --- /dev/null +++ b/sys/arch/landisk/landisk/disksubr.c @@ -0,0 +1,506 @@ +/* $OpenBSD: disksubr.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ + +/* + * Copyright (c) 1996 Theo de Raadt + * Copyright (c) 1982, 1986, 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/buf.h> +#include <sys/device.h> +#include <sys/disklabel.h> +#include <sys/syslog.h> +#include <sys/disk.h> + +/* + * Attempt to read a disk label from a device + * using the indicated strategy routine. + * The label must be partly set up before this: + * secpercyl, secsize and anything required for a block i/o read + * operation in the driver's strategy/start routines + * must be filled in before calling us. + * + * If dos partition table requested, attempt to load it and + * find disklabel inside a DOS partition. Also, if bad block + * table needed, attempt to extract it as well. Return buffer + * for use in signalling errors if requested. + * + * We would like to check if each MBR has a valid DOSMBR_SIGNATURE, but + * we cannot because it doesn't always exist. So.. we assume the + * MBR is valid. + * + * Returns null on success and an error string on failure. + */ +char * +readdisklabel(dev, strat, lp, osdep, spoofonly) + dev_t dev; + void (*strat)(struct buf *); + register struct disklabel *lp; + struct cpu_disklabel *osdep; + int spoofonly; +{ + struct dos_partition *dp = osdep->dosparts, *dp2; + struct buf *bp = NULL; + struct disklabel *dlp; + char *msg = NULL, *cp; + int dospartoff, cyl, i, ourpart = -1; + + /* minimal requirements for archetypal disk label */ + if (lp->d_secsize < DEV_BSIZE) + lp->d_secsize = DEV_BSIZE; + if (lp->d_secperunit == 0) + lp->d_secperunit = 0x1fffffff; + if (lp->d_secpercyl == 0) + return ("invalid geometry"); + lp->d_npartitions = RAW_PART + 1; + for (i = 0; i < RAW_PART; i++) { + lp->d_partitions[i].p_size = 0; + lp->d_partitions[i].p_offset = 0; + } + if (lp->d_partitions[i].p_size == 0) + lp->d_partitions[i].p_size = lp->d_secperunit; + lp->d_partitions[i].p_offset = 0; + + /* get a buffer and initialize it */ + bp = geteblk((int)lp->d_secsize); + bp->b_dev = dev; + + /* do dos partitions in the process of getting disklabel? */ + dospartoff = 0; + cyl = LABELSECTOR / lp->d_secpercyl; + if (dp) { + daddr_t part_blkno = DOSBBSECTOR; + unsigned long extoff = 0; + int wander = 1, n = 0, loop = 0; + + /* + * Read dos partition table, follow extended partitions. + * Map the partitions to disklabel entries i-p + */ + while (wander && n < 8 && loop < 8) { + loop++; + wander = 0; + if (part_blkno < extoff) + part_blkno = extoff; + + /* read boot record */ + bp->b_blkno = part_blkno; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + bp->b_cylinder = part_blkno / lp->d_secpercyl; + (*strat)(bp); + + /* if successful, wander through dos partition table */ + if (biowait(bp)) { + msg = "dos partition I/O error"; + goto done; + } + bcopy(bp->b_data + DOSPARTOFF, dp, NDOSPART * sizeof(*dp)); + + if (ourpart == -1) { + /* Search for our MBR partition */ + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; + i++, dp2++) + if (letoh32(dp2->dp_size) && + dp2->dp_typ == DOSPTYP_OPENBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; + i++, dp2++) + if (letoh32(dp2->dp_size) && + dp2->dp_typ == DOSPTYP_FREEBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; + i++, dp2++) + if (letoh32(dp2->dp_size) && + dp2->dp_typ == DOSPTYP_NETBSD) + ourpart = i; + if (ourpart == -1) + goto donot; + /* + * This is our MBR partition. need sector address + * for SCSI/IDE, cylinder for ESDI/ST506/RLL + */ + dp2 = &dp[ourpart]; + dospartoff = letoh32(dp2->dp_start) + part_blkno; + cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect); + + /* XXX build a temporary disklabel */ + lp->d_partitions[0].p_size = letoh32(dp2->dp_size); + lp->d_partitions[0].p_offset = + letoh32(dp2->dp_start) + part_blkno; + if (lp->d_ntracks == 0) + lp->d_ntracks = dp2->dp_ehd + 1; + if (lp->d_nsectors == 0) + lp->d_nsectors = DPSECT(dp2->dp_esect); + if (lp->d_secpercyl == 0) + lp->d_secpercyl = lp->d_ntracks * + lp->d_nsectors; + } +donot: + /* + * In case the disklabel read below fails, we want to + * provide a fake label in i-p. + */ + for (dp2=dp, i=0; i < NDOSPART && n < 8; i++, dp2++) { + struct partition *pp = &lp->d_partitions[8+n]; + + if (dp2->dp_typ == DOSPTYP_OPENBSD) + continue; + if (letoh32(dp2->dp_size) > lp->d_secperunit) + continue; + if (letoh32(dp2->dp_size)) + pp->p_size = letoh32(dp2->dp_size); + if (letoh32(dp2->dp_start)) + pp->p_offset = + letoh32(dp2->dp_start) + part_blkno; + + switch (dp2->dp_typ) { + case DOSPTYP_UNUSED: + for (cp = (char *)dp2; + cp < (char *)(dp2 + 1); cp++) + if (*cp) + break; + /* + * Was it all zeroes? If so, it is + * an unused entry that we don't + * want to show. + */ + if (cp == (char *)(dp2 + 1)) + continue; + lp->d_partitions[8 + n++].p_fstype = + FS_UNUSED; + break; + + case DOSPTYP_LINUX: + pp->p_fstype = FS_EXT2FS; + n++; + break; + + case DOSPTYP_FAT12: + case DOSPTYP_FAT16S: + case DOSPTYP_FAT16B: + case DOSPTYP_FAT32: + case DOSPTYP_FAT32L: + pp->p_fstype = FS_MSDOS; + n++; + break; + case DOSPTYP_EXTEND: + case DOSPTYP_EXTENDL: + part_blkno = letoh32(dp2->dp_start) + extoff; + if (!extoff) { + extoff = letoh32(dp2->dp_start); + part_blkno = 0; + } + wander = 1; + break; + default: + pp->p_fstype = FS_OTHER; + n++; + break; + } + } + } + lp->d_bbsize = 8192; + lp->d_sbsize = 64*1024; /* XXX ? */ + lp->d_npartitions = MAXPARTITIONS; + } + + /* don't read the on-disk label if we are in spoofed-only mode */ + if (spoofonly) + goto done; + + /* next, dig out disk label */ + bp->b_blkno = dospartoff + LABELSECTOR; + bp->b_cylinder = cyl; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + (*strat)(bp); + + /* if successful, locate disk label within block and validate */ + if (biowait(bp)) { + /* XXX we return the faked label built so far */ + msg = "disk label I/O error"; + goto done; + } + for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *)(bp->b_data + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { + if (msg == NULL) + msg = "no disk label"; + } else if (dlp->d_npartitions > MAXPARTITIONS || + dkcksum(dlp) != 0) + msg = "disk label corrupted"; + else { + *lp = *dlp; + msg = NULL; + break; + } + } + + if (msg) { +#if defined(CD9660) + if (iso_disklabelspoof(dev, strat, lp) == 0) + msg = NULL; +#endif +#if defined(UDF) + if (msg && udf_disklabelspoof(dev, strat, lp) == 0) + msg = NULL; +#endif + goto done; + } + + /* obtain bad sector table if requested and present */ + +done: + if (bp) { + bp->b_flags |= B_INVAL; + brelse(bp); + } + return (msg); +} + +/* + * Check new disk label for sensibility + * before setting it. + */ +int +setdisklabel(olp, nlp, openmask, osdep) + register struct disklabel *olp, *nlp; + u_long openmask; + struct cpu_disklabel *osdep; +{ + register int i; + register struct partition *opp, *npp; + + /* sanity clause */ + if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 || + (nlp->d_secsize % DEV_BSIZE) != 0) + return(EINVAL); + + /* special case to allow disklabel to be invalidated */ + if (nlp->d_magic == 0xffffffff) { + *olp = *nlp; + return (0); + } + + if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC || + dkcksum(nlp) != 0) + return (EINVAL); + + /* XXX missing check if other dos partitions will be overwritten */ + + while (openmask != 0) { + i = ffs(openmask) - 1; + openmask &= ~(1 << i); + if (nlp->d_npartitions <= i) + return (EBUSY); + opp = &olp->d_partitions[i]; + npp = &nlp->d_partitions[i]; + if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size) + return (EBUSY); + /* + * Copy internally-set partition information + * if new label doesn't include it. XXX + */ + if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) { + npp->p_fstype = opp->p_fstype; + npp->p_fsize = opp->p_fsize; + npp->p_frag = opp->p_frag; + npp->p_cpg = opp->p_cpg; + } + } + nlp->d_checksum = 0; + nlp->d_checksum = dkcksum(nlp); + *olp = *nlp; + return (0); +} + + +/* + * Write disk label back to device after modification. + * XXX cannot handle OpenBSD partitions in extended partitions! + */ +int +writedisklabel(dev, strat, lp, osdep) + dev_t dev; + void (*strat)(struct buf *); + register struct disklabel *lp; + struct cpu_disklabel *osdep; +{ + struct dos_partition *dp = osdep->dosparts, *dp2; + struct buf *bp; + struct disklabel *dlp; + int error, dospartoff, cyl, i; + int ourpart = -1; + + /* get a buffer and initialize it */ + bp = geteblk((int)lp->d_secsize); + bp->b_dev = dev; + + /* do dos partitions in the process of getting disklabel? */ + dospartoff = 0; + cyl = LABELSECTOR / lp->d_secpercyl; + if (dp) { + /* read master boot record */ + bp->b_blkno = DOSBBSECTOR; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + bp->b_cylinder = DOSBBSECTOR / lp->d_secpercyl; + (*strat)(bp); + + if ((error = biowait(bp)) != 0) + goto done; + + /* XXX how do we check veracity/bounds of this? */ + bcopy(bp->b_data + DOSPARTOFF, dp, + NDOSPART * sizeof(*dp)); + + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) + if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_OPENBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) + if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_FREEBSD) + ourpart = i; + for (dp2=dp, i=0; i < NDOSPART && ourpart == -1; i++, dp2++) + if (letoh32(dp2->dp_size) && dp2->dp_typ == DOSPTYP_NETBSD) + ourpart = i; + + if (ourpart != -1) { + dp2 = &dp[ourpart]; + + /* + * need sector address for SCSI/IDE, + * cylinder for ESDI/ST506/RLL + */ + dospartoff = letoh32(dp2->dp_start); + cyl = DPCYL(dp2->dp_scyl, dp2->dp_ssect); + } + } + + /* next, dig out disk label */ + bp->b_blkno = dospartoff + LABELSECTOR; + bp->b_cylinder = cyl; + bp->b_bcount = lp->d_secsize; + bp->b_flags = B_BUSY | B_READ; + (*strat)(bp); + + /* if successful, locate disk label within block and validate */ + if ((error = biowait(bp)) != 0) + goto done; + for (dlp = (struct disklabel *)bp->b_data; + dlp <= (struct disklabel *)(bp->b_data + lp->d_secsize - sizeof(*dlp)); + dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { + if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC && + dkcksum(dlp) == 0) { + *dlp = *lp; + bp->b_flags = B_BUSY | B_WRITE; + (*strat)(bp); + error = biowait(bp); + goto done; + } + } + + /* Write it in the regular place. */ + *(struct disklabel *)bp->b_data = *lp; + bp->b_flags = B_BUSY | B_WRITE; + (*strat)(bp); + error = biowait(bp); + goto done; + +done: + bp->b_flags |= B_INVAL; + brelse(bp); + return (error); +} + +/* + * Determine the size of the transfer, and make sure it is + * within the boundaries of the partition. Adjust transfer + * if needed, and signal errors or early completion. + */ +int +bounds_check_with_label(bp, lp, osdep, wlabel) + struct buf *bp; + struct disklabel *lp; + struct cpu_disklabel *osdep; + int wlabel; +{ +#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) + struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); + int labelsector = blockpersec(lp->d_partitions[RAW_PART].p_offset, lp) + + LABELSECTOR; + int sz = howmany(bp->b_bcount, DEV_BSIZE); + + /* avoid division by zero */ + if (lp->d_secpercyl == 0) { + bp->b_error = EINVAL; + goto bad; + } + + /* beyond partition? */ + if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) { + sz = blockpersec(p->p_size, lp) - bp->b_blkno; + if (sz == 0) { + /* If exactly at end of disk, return EOF. */ + bp->b_resid = bp->b_bcount; + goto done; + } + if (sz < 0) { + /* If past end of disk, return EINVAL. */ + bp->b_error = EINVAL; + goto bad; + } + /* Otherwise, truncate request. */ + bp->b_bcount = sz << DEV_BSHIFT; + } + + /* Overwriting disk label? */ + if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsector && +#if LABELSECTOR != 0 + bp->b_blkno + blockpersec(p->p_offset, lp) + sz > labelsector && +#endif + (bp->b_flags & B_READ) == 0 && !wlabel) { + bp->b_error = EROFS; + goto bad; + } + + /* calculate cylinder for disksort to order transfers with */ + bp->b_cylinder = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + lp->d_secpercyl; + return (1); + +bad: + bp->b_flags |= B_ERROR; +done: + return (0); +} diff --git a/sys/arch/landisk/landisk/intr.c b/sys/arch/landisk/landisk/intr.c new file mode 100644 index 00000000000..dc90430df12 --- /dev/null +++ b/sys/arch/landisk/landisk/intr.c @@ -0,0 +1,364 @@ +/* $OpenBSD: intr.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: intr.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2005 NONAKA Kimihiro + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/malloc.h> +#include <sys/device.h> +#include <sys/evcount.h> + +#include <sh/trap.h> + +#include <machine/intr.h> + +#define _N_EXTINTR 8 + +#define LANDISK_INTEN 0xb0000005 +#define INTEN_ALL_MASK 0x00 + +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + struct intrhand *ih_next; + int ih_enable; + int ih_level; + int ih_irq; + struct evcount ih_cnt; +}; + +struct extintr_handler { + int (*eih_func)(void *eih_arg); + void *eih_arg; + struct intrhand *eih_ih; + int eih_nih; +}; + +static struct extintr_handler extintr_handler[_N_EXTINTR]; + +static int fakeintr(void *arg); +static int extintr_intr_handler(void *arg); + +void +intc_intr(int ssr, int spc, int ssp) +{ + struct intc_intrhand *ih; + struct clockframe cf; + int evtcode; + + evtcode = _reg_read_4(SH4_INTEVT); + ih = EVTCODE_IH(evtcode); + KDASSERT(ih->ih_func); + + switch (evtcode) { +#if 0 +#define IRL(irq) (0x200 + ((irq) << 5)) + case IRL(5): case IRL(6): case IRL(7): case IRL(8): + case IRL(9): case IRL(10): case IRL(11): case IRL(12): + { + int level; + uint8_t inten, bit; + + bit = 1 << (EVTCODE_TO_MAP_INDEX(evtcode) - 5); + inten = _reg_read_1(LANDISK_INTEN); + _reg_write_1(LANDISK_INTEN, inten & ~bit); + level = (_IPL_NSOFT + 1) << 4; /* disable softintr */ + ssr &= 0xf0; + if (level < ssr) + level = ssr; + (void)_cpu_intr_resume(level); + (*ih->ih_func)(ih->ih_arg); + _reg_write_1(LANDISK_INTEN, inten); + break; + } +#endif + default: + (void)_cpu_intr_resume(ih->ih_level); + (*ih->ih_func)(ih->ih_arg); + break; + + case SH_INTEVT_TMU0_TUNI0: + (void)_cpu_intr_resume(ih->ih_level); + cf.spc = spc; + cf.ssr = ssr; + cf.ssp = ssp; + (*ih->ih_func)(&cf); + break; + + case SH_INTEVT_NMI: + printf("NMI ignored.\n"); + break; + } +} + +void +intr_init(void) +{ + _reg_write_1(LANDISK_INTEN, INTEN_ALL_MASK); +} + +void * +extintr_establish(int irq, int level, int (*ih_fun)(void *), void *ih_arg, + const char *ih_name) +{ + static struct intrhand fakehand = {fakeintr}; + struct extintr_handler *eih; + struct intrhand **p, *q, *ih; + int evtcode; + int s; + + KDASSERT(irq >= 5 && irq <= 12); + + ih = malloc(sizeof(*ih), M_DEVBUF, cold ? M_NOWAIT : M_WAITOK); + if (ih == NULL) + panic("intr_establish: can't malloc handler info"); + + s = _cpu_intr_suspend(); + + switch (level) { + default: +#if defined(DEBUG) + panic("extintr_establish: unknown level %d", level); + /*NOTREACHED*/ +#endif + case IPL_BIO: + case IPL_NET: + case IPL_TTY: + break; + } + + eih = &extintr_handler[irq - 5]; + if (eih->eih_func == NULL) { + evtcode = 0x200 + (irq << 5); + eih->eih_func = intc_intr_establish(evtcode, IST_LEVEL, level, + extintr_intr_handler, eih, ih_name); + } + + /* + * Figure out where to put the handler. + * This is O(N^2), but we want to preserve the order, and N is + * generally small. + */ + for (p = &eih->eih_ih; (q = *p) != NULL; p = &q->ih_next) + continue; + + /* + * Actually install a fake handler momentarily, since we might be doing + * this with interrupts enabled and don't want the real routine called + * until masking is set up. + */ + fakehand.ih_level = level; + *p = &fakehand; + + /* + * Poke the real handler in now. + */ + memset(ih, 0, sizeof(*ih)); + ih->ih_fun = ih_fun; + ih->ih_arg = ih_arg; + ih->ih_next = NULL; + ih->ih_enable = 1; + ih->ih_level = level; + ih->ih_irq = irq - 5; +#if 0 + evcnt_attach_dynamic(&ih->ih_evcnt, EVCNT_TYPE_INTR, + NULL, "ext", name); +#endif + *p = ih; + + if (++eih->eih_nih == 1) { + /* Unmask interrupt */ + _reg_bset_1(LANDISK_INTEN, (1 << (irq - 5))); + } + + splx(s); + + return (ih); +} + +void +extintr_disestablish(void *aux) +{ + struct intrhand *ih = aux; + struct intrhand **p, *q; + struct extintr_handler *eih; + int irq; + int s; + + KDASSERT(ih != NULL); + + s = _cpu_intr_suspend(); + + irq = ih->ih_irq; + eih = &extintr_handler[irq]; + + /* + * Remove the handler from the chain. + * This is O(n^2), too. + */ + for (p = &eih->eih_ih; (q = *p) != NULL && q != ih; p = &q->ih_next) + continue; + if (q == NULL) + panic("extintr_disestablish: handler not registered"); + + *p = q->ih_next; + +#if 0 + evcnt_detach(&ih->ih_evcnt); +#endif + + free((void *)ih, M_DEVBUF); + + if (--eih->eih_nih == 0) { + intc_intr_disestablish(eih->eih_func); + + /* Mask interrupt */ + _reg_bclr_1(LANDISK_INTEN, (1 << irq)); + } + + splx(s); +} + +void +extintr_enable(void *aux) +{ + struct intrhand *ih = aux; + struct intrhand *p, *q; + struct extintr_handler *eih; + int irq; + int cnt; + int s; + + KDASSERT(ih != NULL); + + s = _cpu_intr_suspend(); + + irq = ih->ih_irq; + KDASSERT(irq >= 0 && irq < 8); + eih = &extintr_handler[irq]; + for (cnt = 0, p = eih->eih_ih, q = NULL; p != NULL; p = p->ih_next) { + if (p->ih_enable) { + cnt++; + } + if (p == ih) { + q = p; + p->ih_enable = 1; + } + } + KDASSERT(q != NULL); + + if (cnt == 0) { + /* Unmask interrupt */ + _reg_bset_1(LANDISK_INTEN, (1 << irq)); + } + + splx(s); +} + +void +extintr_disable(void *aux) +{ + struct intrhand *ih = aux; + struct intrhand *p, *q; + struct extintr_handler *eih; + int irq; + int cnt; + int s; + + KDASSERT(ih != NULL); + + s = _cpu_intr_suspend(); + + irq = ih->ih_irq; + KDASSERT(irq >= 0 && irq < 8); + eih = &extintr_handler[irq]; + for (cnt = 0, p = eih->eih_ih, q = NULL; p != NULL; p = p->ih_next) { + if (p == ih) { + q = p; + p->ih_enable = 0; + } + if (!ih->ih_enable) { + cnt++; + } + } + KDASSERT(q != NULL); + + if (cnt == 0) { + /* Mask interrupt */ + _reg_bclr_1(LANDISK_INTEN, (1 << irq)); + } + + splx(s); +} + +void +extintr_disable_by_num(int irq) +{ + struct extintr_handler *eih; + struct intrhand *ih; + int s; + + KDASSERT(irq >= 5 && irq <= 12); + + s = _cpu_intr_suspend(); + eih = &extintr_handler[irq - 5]; + for (ih = eih->eih_ih; ih != NULL; ih = ih->ih_next) { + ih->ih_enable = 0; + } + /* Mask interrupt */ + _reg_bclr_1(LANDISK_INTEN, (1 << irq)); + splx(s); +} + +static int +fakeintr(void *arg) +{ + return 0; +} + +static int +extintr_intr_handler(void *arg) +{ + struct extintr_handler *eih = arg; + struct intrhand *ih; + int r; + + if (__predict_true(eih != NULL)) { + for (ih = eih->eih_ih; ih != NULL; ih = ih->ih_next) { + if (__predict_true(ih->ih_enable)) { + r = (*ih->ih_fun)(ih->ih_arg); + if (__predict_true(r != 0)) { + ih->ih_cnt.ec_count++; + } + } + } + return 1; + } + return 0; +} diff --git a/sys/arch/landisk/landisk/landiskreg.h b/sys/arch/landisk/landisk/landiskreg.h new file mode 100644 index 00000000000..8e2b153ebd8 --- /dev/null +++ b/sys/arch/landisk/landisk/landiskreg.h @@ -0,0 +1,70 @@ +/* $OpenBSD: landiskreg.h,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: landiskreg.h,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2005 NONAKA Kimihiro + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef LANDISKREG_H__ +#define LANDISKREG_H__ + +#define LANDISK_BTNSTAT 0xb0000002 +#define LANDISK_PWRMNG 0xb0000003 /* write-only */ +#define LANDISK_INTEN 0xb0000005 +#define LANDISK_PWRSW_INTCLR 0xb0000006 + +#define BTN_SELECT_BIT (1 << 0) +#define BTN_COPY_BIT (1 << 1) +#define BTN_REMOVE_BIT (1 << 2) +#define BTN_POWER_BIT (1 << 4) +#define BTN_RESET_BIT (1 << 5) +#define BTN_ALL_BIT (BTN_SELECT_BIT \ + | BTN_COPY_BIT \ + | BTN_REMOVE_BIT \ + | BTN_RESET_BIT) + +#define PWRMNG_POWEROFF 0x01 +#define PWRMNG_RTC_CE 0x02 + +#define INTEN_ALL_MASK 0x00 +#define INTEN_PCI0 0x01 /* rtk/ehci */ +#define INTEN_PCI1 0x02 /* acardide */ +#define INTEN_PCI2 0x04 /* ochi0 */ +#define INTEN_PCI3 0x08 /* ochi1 */ +#define INTEN_ICONNECT 0x10 /* wdc1 at obio */ +#define INTEN_CFIDE 0x20 /* wdc0 at obio */ +#define INTEN_PWRSW 0x40 /* pwrsw at obio */ +#define INTEN_BTN 0x80 /* btn at obio */ + +#define LANDISK_INTR_PCI0 5 /* rtk/ehci */ +#define LANDISK_INTR_PCI1 6 /* acardide (LANDISK) */ +#define LANDISK_INTR_PCI2 7 /* ohci0 */ +#define LANDISK_INTR_PCI3 8 /* ochi1 */ +#define LANDISK_INTR_ICONNECT 9 /* wdc1 (LAN-iCN2 iConnect) */ +#define LANDISK_INTR_CFIDE 10 /* wdc0 (LAN-iCN2/USL-5P CF) */ +#define LANDISK_INTR_PWRSW 11 /* pwrsw */ +#define LANDISK_INTR_BTN 12 /* btn (USL-5P) */ + +#endif /* LANDISKREG_H__ */ diff --git a/sys/arch/landisk/landisk/locore.S b/sys/arch/landisk/landisk/locore.S new file mode 100644 index 00000000000..4d0215e65c3 --- /dev/null +++ b/sys/arch/landisk/landisk/locore.S @@ -0,0 +1,79 @@ +/* $OpenBSD: locore.S,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: locore.S,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "assym.h" + +#include <sh/asm.h> +#include <sh/locore.h> +#include <sh/trap.h> +#include <sh/mmu_sh4.h> + +/* + * void start(int howto, void *bootinfo); + * Kernel entry point. + */ +NENTRY(start) +ALTENTRY(kernel_text) + /* Set bootstrap stack pointer */ + mov.l _L.bootstrap_stack, r15 + + /* Mask all interrupt */ + __INTR_MASK(r0, r1) + + /* MMU off */ + mov.l _L.MMUCR, r0 + xor r1, r1 + mov.l r1, @r0 + + /* Make sure to change register bank 0 */ + mov #0x20, r1 + stc sr, r0 + swap.b r1, r1 + swap.w r1, r1 + not r1, r1 + and r1, r0 + ldc r0, sr /* SR.RB = 0 */ + + /* Go! */ + mov.l _L.landisk_startup, r0 + jmp @r0 + nop + + /* NOTREACHED */ + .align 2 +_L.landisk_startup: .long _C_LABEL(landisk_startup) +_L.bootstrap_stack: .long _C_LABEL(start) +_L.MMUCR: .long SH4_MMUCR diff --git a/sys/arch/landisk/landisk/machdep.c b/sys/arch/landisk/landisk/machdep.c new file mode 100644 index 00000000000..b9f6679a1df --- /dev/null +++ b/sys/arch/landisk/landisk/machdep.c @@ -0,0 +1,385 @@ +/* $OpenBSD: machdep.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: machdep.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1982, 1987, 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)machdep.c 7.4 (Berkeley) 6/3/91 + */ + +#include "ksyms.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/user.h> +#include <sys/mount.h> +#include <sys/reboot.h> +#include <sys/sysctl.h> + +#include <uvm/uvm_extern.h> + +#include <dev/cons.h> + +#include <sh/bscreg.h> +#include <sh/cpgreg.h> +#include <sh/trap.h> + +#include <sh/cache.h> +#include <sh/cache_sh4.h> +#include <sh/mmu_sh4.h> + +#include <machine/bootinfo.h> +#include <machine/cpu.h> + +#include <landisk/landisk/landiskreg.h> + +#ifdef DDB +#include <machine/db_machdep.h> +#include <ddb/db_extern.h> +#include <ddb/db_interface.h> +#endif + +/* the following is used externally (sysctl_hw) */ +char machine[] = MACHINE; /* landisk */ + +struct bootinfo _bootinfo; +struct bootinfo *bootinfo; + +__dead void landisk_startup(int, void *); +__dead void main(void); + +void +cpu_startup(void) +{ + extern char cpu_model[120]; + + /* XXX: show model (LANDISK/USL-5P) */ + strlcpy(cpu_model, "I-O DATA USL-5P\n", sizeof cpu_model); + + sh_startup(); +} + +vaddr_t kernend; /* used by /dev/mem too */ + +void +landisk_startup(int howto, void *bi) +{ + extern char edata[], end[]; + + /* Clear bss */ + memset(edata, 0, end - edata); + +/* XXX symbols */ + /* Start to determine heap area */ + kernend = (vaddr_t)round_page((vaddr_t)end); + + /* Copy bootinfo */ + bootinfo = &_bootinfo; + memcpy(bootinfo, bi, sizeof(struct bootinfo)); + boothowto = howto; + + /* Initialize CPU ops. */ + sh_cpu_init(CPU_ARCH_SH4, CPU_PRODUCT_7751R); + + /* Initialize early console */ + consinit(); + + /* Load memory to UVM */ + physmem = atop(IOM_RAM_SIZE); + kernend = atop(round_page(SH3_P1SEG_TO_PHYS(kernend))); + uvm_page_physload(atop(IOM_RAM_BEGIN), + atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), kernend, + atop(IOM_RAM_BEGIN + IOM_RAM_SIZE), VM_FREELIST_DEFAULT); + + /* Initialize proc0 u-area */ + sh_proc0_init(); + + /* Initialize pmap and start to address translation */ + pmap_bootstrap(); + +#if defined(DDB) + db_machine_init(); + ddb_init(); + if (boothowto & RB_KDB) { + Debugger(); + } +#endif + + /* Jump to main */ + __asm volatile( + "jmp @%0;" + "mov %1, sp" + :: "r" (main), "r" (proc0.p_md.md_pcb->pcb_sf.sf_r7_bank)); + /* NOTREACHED */ + for (;;) ; +} + +void * +lookup_bootinfo(int type) +{ + struct btinfo_common *help; + int n = bootinfo->nentries; + + help = (struct btinfo_common *)(bootinfo->info); + while (n--) { + if (help->type == type) + return (help); + help = (struct btinfo_common *)((char *)help + help->len); + } + return (NULL); +} + +void +boot(int howto) +{ + + if (cold) { + howto |= RB_HALT; + goto haltsys; + } + + boothowto = howto; + if ((howto & RB_NOSYNC) == 0) { + vfs_shutdown(); + /* + * If we've been adjusting the clock, the todr + * will be out of synch; adjust it now. + */ + resettodr(); + } + + /* wait 1s */ + delay(1 * 1000 * 1000); + + /* Disable interrupts. */ + splhigh(); + + /* Do a dump if requested. */ + if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) { + dumpsys(); + } + +haltsys: + doshutdownhooks(); + + if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { + _reg_write_1(LANDISK_PWRMNG, PWRMNG_POWEROFF); + delay(1 * 1000 * 1000); + printf("POWEROFF FAILED!\n"); + } + + if (howto & RB_HALT) { + printf("\n"); + printf("The operating system has halted.\n"); + printf("Please press any key to reboot.\n\n"); + cngetc(); + } + + printf("rebooting...\n"); + machine_reset(); + + /*NOTREACHED*/ + for (;;) { + continue; + } +} + +void +machine_reset(void) +{ + _cpu_exception_suspend(); + _reg_write_4(SH_(EXPEVT), EXPEVT_RESET_MANUAL); + (void)*(volatile uint32_t *)0x80000001; /* CPU shutdown */ + + /*NOTREACHED*/ + for (;;) { + continue; + } +} + +#if !defined(DONT_INIT_BSC) +/* + * InitializeBsc + * : BSC(Bus State Controller) + */ +void InitializeBsc(void); + +void +InitializeBsc(void) +{ + + /* + * Drive RAS,CAS in stand by mode and bus release mode + * Area0 = Normal memory, Area5,6=Normal(no burst) + * Area2 = Normal memory, Area3 = SDRAM, Area5 = Normal memory + * Area4 = Normal Memory + * Area6 = Normal memory + */ + _reg_write_4(SH4_BCR1, BSC_BCR1_VAL); + + /* + * Bus Width + * Area4: Bus width = 16bit + * Area6,5 = 16bit + * Area1 = 8bit + * Area2,3: Bus width = 32bit + */ + _reg_write_2(SH4_BCR2, BSC_BCR2_VAL); + +#if defined(SH4) && defined(SH7751R) + if (cpu_product == CPU_PRODUCT_7751R) { +#ifdef BSC_BCR3_VAL + _reg_write_2(SH4_BCR3, BSC_BCR3_VAL); +#endif +#ifdef BSC_BCR4_VAL + _reg_write_4(SH4_BCR4, BSC_BCR4_VAL); +#endif + } +#endif /* SH4 && SH7751R */ + + /* + * Idle cycle number in transition area and read to write + * Area6 = 3, Area5 = 3, Area4 = 3, Area3 = 3, Area2 = 3 + * Area1 = 3, Area0 = 3 + */ + _reg_write_4(SH4_WCR1, BSC_WCR1_VAL); + + /* + * Wait cycle + * Area 6 = 6 + * Area 5 = 2 + * Area 4 = 10 + * Area 3 = 3 + * Area 2,1 = 3 + * Area 0 = 6 + */ + _reg_write_4(SH4_WCR2, BSC_WCR2_VAL); + +#ifdef BSC_WCR3_VAL + _reg_write_4(SH4_WCR3, BSC_WCR3_VAL); +#endif + + /* + * RAS pre-charge = 2cycle, RAS-CAS delay = 3 cycle, + * write pre-charge=1cycle + * CAS before RAS refresh RAS assert time = 3 cycle + * Disable burst, Bus size=32bit, Column Address=10bit, Refresh ON + * CAS before RAS refresh ON, EDO DRAM + */ + _reg_write_4(SH4_MCR, BSC_MCR_VAL); + +#ifdef BSC_SDMR2_VAL + _reg_write_1(BSC_SDMR2_VAL, 0); +#endif + +#ifdef BSC_SDMR3_VAL + _reg_write_1(BSC_SDMR3_VAL, 0); +#endif /* BSC_SDMR3_VAL */ + + /* + * PCMCIA Control Register + * OE/WE assert delay 3.5 cycle + * OE/WE negate-address delay 3.5 cycle + */ +#ifdef BSC_PCR_VAL + _reg_write_2(SH4_PCR, BSC_PCR_VAL); +#endif + + /* + * Refresh Timer Control/Status Register + * Disable interrupt by CMF, closk 1/16, Disable OVF interrupt + * Count Limit = 1024 + * In following statement, the reason why high byte = 0xa5(a4 in RFCR) + * is the rule of SH3 in writing these register. + */ + _reg_write_2(SH4_RTCSR, BSC_RTCSR_VAL); + + /* + * Refresh Timer Counter + * Initialize to 0 + */ +#ifdef BSC_RTCNT_VAL + _reg_write_2(SH4_RTCNT, BSC_RTCNT_VAL); +#endif + + /* set Refresh Time Constant Register */ + _reg_write_2(SH4_RTCOR, BSC_RTCOR_VAL); + + /* init Refresh Count Register */ +#ifdef BSC_RFCR_VAL + _reg_write_2(SH4_RFCR, BSC_RFCR_VAL); +#endif + + /* + * Clock Pulse Generator + */ + /* Set Clock mode (make internal clock double speed) */ + _reg_write_2(SH4_FRQCR, FRQCR_VAL); +} +#endif /* !DONT_INIT_BSC */ diff --git a/sys/arch/landisk/landisk/mainbus.c b/sys/arch/landisk/landisk/mainbus.c new file mode 100644 index 00000000000..872d13e265d --- /dev/null +++ b/sys/arch/landisk/landisk/mainbus.c @@ -0,0 +1,116 @@ +/* $OpenBSD: mainbus.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: mainbus.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "obio.h" +#include "pci.h" + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <machine/autoconf.h> +#include <machine/bus.h> + +#include <landisk/dev/obiovar.h> + +static int mainbus_match(struct device *, struct cfdata *, void *); +static void mainbus_attach(struct device *, struct device *, void *); + +CFATTACH_DECL(mainbus, sizeof(struct device), + mainbus_match, mainbus_attach, NULL, NULL); + +static int mainbus_print(void *, const char *); + +/* There can be only one. */ +int mainbus_found = 0; + +static int +mainbus_match(struct device *parent, struct cfdata *cf, void *aux) +{ + + if (mainbus_found) + return (0); + + return (1); +} + +static void +mainbus_attach(struct device *parent, struct device *self, void *aux) +{ + union { + struct mainbus_attach_args mba_mba; + struct confargs mba_ca; + struct obiobus_attach_args mba_oba; + } mba; + + mainbus_found = 1; + + printf("\n"); + + /* CPU */ + memset(&mba, 0, sizeof(mba)); + mba.mba_ca.ca_name = "cpu"; + mba.mba_ca.ca_node = 0; + config_found(self, &mba, mainbus_print); + +#if NPCI > 0 + /* SH PCIC */ + memset(&mba, 0, sizeof(mba)); + mba.mba_mba.ma_name = "shpcic"; + config_found(self, &mba, mainbus_print); +#endif + + /* SH bus */ + memset(&mba, 0, sizeof(mba)); + mba.mba_mba.ma_name = "shb"; + config_found(self, &mba, mainbus_print); + +#if NOBIO > 0 + /* on-board I/O */ + memset(&mba, 0, sizeof(mba)); + mba.mba_oba.oba_busname = "obio"; + mba.mba_oba.oba_iot = &obio_bus_io; + mba.mba_oba.oba_memt = &obio_bus_mem; + config_found(self, &mba, mainbus_print); +#endif +} + +static int +mainbus_print(void *aux, const char *pnp) +{ + + return (pnp ? QUIET : UNCONF); +} diff --git a/sys/arch/landisk/landisk/shpcic_machdep.c b/sys/arch/landisk/landisk/shpcic_machdep.c new file mode 100644 index 00000000000..214aedc5e13 --- /dev/null +++ b/sys/arch/landisk/landisk/shpcic_machdep.c @@ -0,0 +1,265 @@ +/* $OpenBSD: shpcic_machdep.c,v 1.1 2006/10/06 21:16:15 miod Exp $ */ +/* $NetBSD: shpcic_machdep.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ + +/* + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1994 Charles M. Hannum. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles M. Hannum. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Machine-specific functions for PCI autoconfiguration. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/time.h> +#include <sys/systm.h> +#include <sys/errno.h> +#include <sys/extent.h> +#include <sys/device.h> + +#include <uvm/uvm_extern.h> + +#include <dev/pci/pcivar.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcidevs.h> +#if 0 +#include <dev/pci/pciconf.h> +#endif + +#include <machine/bus.h> +#include <machine/intr.h> + +bus_space_tag_t +shpcic_get_bus_io_tag(void) +{ + extern struct _bus_space landisk_pci_bus_io; + + return &landisk_pci_bus_io; +} + +bus_space_tag_t +shpcic_get_bus_mem_tag(void) +{ + extern struct _bus_space landisk_pci_bus_mem; + + return &landisk_pci_bus_mem; +} + +bus_dma_tag_t +shpcic_get_bus_dma_tag(void) +{ + extern struct _bus_dma_tag landisk_bus_dma; + + return &landisk_bus_dma; +} + +void +landisk_pci_attach_hook(struct device *parent, struct device *self, + struct pcibus_attach_args *pba) +{ + /* Nothing to do */ +} + +int +landisk_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) +{ + int pin = pa->pa_intrpin; + int line = pa->pa_intrline; + + if (pin == 0) { + /* No IRQ used. */ + goto bad; + } + + if (pin > 4) { + printf("pci_intr_map: bad interrupt pin %d\n", pin); + goto bad; + } + + if (line == 0 || line == 255) { + printf("pci_intr_map: no mapping for pin %c\n", '@' + pin); + goto bad; + } + + *ihp = line; + return 0; + +bad: + *ihp = -1; + return 1; +} + +const char * +landisk_pci_intr_string(void *v, pci_intr_handle_t ih) +{ + static char irqstr[8]; /* 4 + 2 + NULL + sanity */ + + if (ih == 0) + panic("pci_intr_string: bogus handle 0x%x", ih); + + snprintf(irqstr, sizeof irqstr, "irq %d", ih); + + return (irqstr); +} + +void * +landisk_pci_intr_establish(void *v, pci_intr_handle_t ih, int level, + int (*ih_fun)(void *), void *ih_arg, const char *ih_name) +{ + if (ih == 0) + panic("pci_intr_establish: bogus handle 0x%x", ih); + + return extintr_establish(ih, level, ih_fun, ih_arg, ih_name); +} + +void +landisk_pci_intr_disestablish(void *v, void *cookie) +{ + extintr_disestablish(cookie); +} + +#if 0 +void +landisk_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz, + int *iline) +{ + static const int irq[4] = { 5, 6, 7, 8 }; + + *iline = -1; + if ((dev >= 0 && dev <= 3) && (pin >= 1 && pin <= 4)) { + *iline = irq[(dev + pin - 1) & 3]; + } +} + +int +landisk_pci_conf_hook(void *v, int bus, int dev, int func, pcireg_t id) +{ + + return (PCI_CONF_ALL & ~PCI_CONF_MAP_ROM); +} +#endif + +/* + * shpcic bus space + */ +struct _bus_space landisk_pci_bus_io = +{ + .bs_cookie = NULL, + + .bs_map = shpcic_iomem_map, + .bs_unmap = shpcic_iomem_unmap, + .bs_subregion = shpcic_iomem_subregion, + + .bs_alloc = shpcic_iomem_alloc, + .bs_free = shpcic_iomem_free, + + .bs_r_1 = shpcic_io_read_1, + .bs_r_2 = shpcic_io_read_2, + .bs_r_4 = shpcic_io_read_4, + + .bs_rm_1 = shpcic_io_read_multi_1, + .bs_rm_2 = shpcic_io_read_multi_2, + .bs_rm_4 = shpcic_io_read_multi_4, + + .bs_rr_1 = shpcic_io_read_region_1, + .bs_rr_2 = shpcic_io_read_region_2, + .bs_rr_4 = shpcic_io_read_region_4, + + .bs_w_1 = shpcic_io_write_1, + .bs_w_2 = shpcic_io_write_2, + .bs_w_4 = shpcic_io_write_4, + + .bs_wm_1 = shpcic_io_write_multi_1, + .bs_wm_2 = shpcic_io_write_multi_2, + .bs_wm_4 = shpcic_io_write_multi_4, + + .bs_wr_1 = shpcic_io_write_region_1, + .bs_wr_2 = shpcic_io_write_region_2, + .bs_wr_4 = shpcic_io_write_region_4, + + .bs_sm_1 = shpcic_io_set_multi_1, + .bs_sm_2 = shpcic_io_set_multi_2, + .bs_sm_4 = shpcic_io_set_multi_4, + + .bs_sr_1 = shpcic_io_set_region_1, + .bs_sr_2 = shpcic_io_set_region_2, + .bs_sr_4 = shpcic_io_set_region_4, + + .bs_c_1 = shpcic_io_copy_region_1, + .bs_c_2 = shpcic_io_copy_region_2, + .bs_c_4 = shpcic_io_copy_region_4, +}; + +struct _bus_space landisk_pci_bus_mem = +{ + .bs_cookie = NULL, + + .bs_map = shpcic_iomem_map, + .bs_unmap = shpcic_iomem_unmap, + .bs_subregion = shpcic_iomem_subregion, + + .bs_alloc = shpcic_iomem_alloc, + .bs_free = shpcic_iomem_free, + + .bs_r_1 = shpcic_mem_read_1, + .bs_r_2 = shpcic_mem_read_2, + .bs_r_4 = shpcic_mem_read_4, + + .bs_rm_1 = shpcic_mem_read_multi_1, + .bs_rm_2 = shpcic_mem_read_multi_2, + .bs_rm_4 = shpcic_mem_read_multi_4, + + .bs_rr_1 = shpcic_mem_read_region_1, + .bs_rr_2 = shpcic_mem_read_region_2, + .bs_rr_4 = shpcic_mem_read_region_4, + + .bs_w_1 = shpcic_mem_write_1, + .bs_w_2 = shpcic_mem_write_2, + .bs_w_4 = shpcic_mem_write_4, + + .bs_wm_1 = shpcic_mem_write_multi_1, + .bs_wm_2 = shpcic_mem_write_multi_2, + .bs_wm_4 = shpcic_mem_write_multi_4, + + .bs_wr_1 = shpcic_mem_write_region_1, + .bs_wr_2 = shpcic_mem_write_region_2, + .bs_wr_4 = shpcic_mem_write_region_4, + + .bs_sm_1 = shpcic_mem_set_multi_1, + .bs_sm_2 = shpcic_mem_set_multi_2, + .bs_sm_4 = shpcic_mem_set_multi_4, + + .bs_sr_1 = shpcic_mem_set_region_1, + .bs_sr_2 = shpcic_mem_set_region_2, + .bs_sr_4 = shpcic_mem_set_region_4, + + .bs_c_1 = shpcic_mem_copy_region_1, + .bs_c_2 = shpcic_mem_copy_region_2, + .bs_c_4 = shpcic_mem_copy_region_4, +}; |