Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Import sys/arch/arm32/{shark,ofw} bits of the Digital Network Appliance

Reference Design NetBSD source code, obtained from the pages under
http://www.research.digital.com/SRC/iag .  Some of this code (badly)
needs to be cleaned up, and as-is it doesn't compile.  However, getting
it in the tree is a start.
  • Loading branch information...
commit 3dca576b78ce326325e9b936cd743e812f8c11f5 1 parent a2bca40
cgd authored
Showing with 25,023 additions and 0 deletions.
  1. +78 −0 sys/arch/arm32/ofw/com_ofisa_consolehack.c
  2. +87 −0 sys/arch/arm32/ofw/com_ofisa_machdep.c
  3. +88 −0 sys/arch/arm32/ofw/lpt_ofisa_machdep.c
  4. +94 −0 sys/arch/arm32/ofw/ofisa_machdep.c
  5. +62 −0 sys/arch/arm32/ofw/ofisa_machdep.h
  6. +131 −0 sys/arch/arm32/ofw/ofisacs.c
  7. +127 −0 sys/arch/arm32/ofw/ofisaess.c
  8. +123 −0 sys/arch/arm32/ofw/ofisapc.c
  9. +131 −0 sys/arch/arm32/ofw/ofisascr.c
  10. +219 −0 sys/arch/arm32/ofw/ofrom.c
  11. +284 −0 sys/arch/arm32/ofw/oftodclock.c
  12. +2,047 −0 sys/arch/arm32/ofw/ofw.c
  13. +671 −0 sys/arch/arm32/ofw/ofw_irq.S
  14. +549 −0 sys/arch/arm32/ofw/ofw_irqhandler.c
  15. +402 −0 sys/arch/arm32/ofw/ofwgencfg_clock.c
  16. +388 −0 sys/arch/arm32/ofw/ofwgencfg_machdep.c
  17. +694 −0 sys/arch/arm32/ofw/openfirm.c
  18. +86 −0 sys/arch/arm32/ofw/wdc_ofisa_machdep.c
  19. +47 −0 sys/arch/arm32/shark/display.h
  20. +148 −0 sys/arch/arm32/shark/fiq.S
  21. +50 −0 sys/arch/arm32/shark/fiq.h
  22. +195 −0 sys/arch/arm32/shark/hat.c
  23. +89 −0 sys/arch/arm32/shark/hat.h
  24. +408 −0 sys/arch/arm32/shark/i8042.c
  25. +295 −0 sys/arch/arm32/shark/i8042reg.h
  26. +31 −0 sys/arch/arm32/shark/kbdreg.h
  27. +591 −0 sys/arch/arm32/shark/lpt.c
  28. +358 −0 sys/arch/arm32/shark/ns87307.c
  29. +424 −0 sys/arch/arm32/shark/ns87307reg.h
  30. +3,792 −0 sys/arch/arm32/shark/pccons.c
  31. +983 −0 sys/arch/arm32/shark/pms.c
  32. +717 −0 sys/arch/arm32/shark/profile.c
  33. +4,230 −0 sys/arch/arm32/shark/scr.c
  34. +1 −0  sys/arch/arm32/shark/scr.h
  35. +772 −0 sys/arch/arm32/shark/sequoia.c
  36. +5,129 −0 sys/arch/arm32/shark/sequoia.h
  37. +502 −0 sys/arch/arm32/shark/shark_machdep.c
View
78 sys/arch/arm32/ofw/com_ofisa_consolehack.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * OFW Attachment for 'com' serial driver
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/tty.h>
+
+#include <machine/intr.h>
+#include <machine/bus.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
+
+#include <arm32/isa/isa_machdep.h> /* XXX for space tags */
+
+#include <dev/cons.h>
+
+void
+comcnprobe(cp)
+ struct consdev *cp;
+{
+
+#ifdef COMCONSOLE
+ cp->cn_pri = CN_REMOTE; /* Force a serial port console */
+#else
+ cp->cn_pri = CN_NORMAL;
+#endif
+}
+
+void
+comcninit(cp)
+ struct consdev *cp;
+{
+
+#ifndef CONMODE
+#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
+#endif
+
+ if (comcnattach(&isa_io_bs_tag, 0x3f8, 9600, COM_FREQ, CONMODE))
+ panic("can't init serial console @%x", 0x3f8);
+}
View
87 sys/arch/arm32/ofw/com_ofisa_machdep.c
@@ -0,0 +1,87 @@
+/* $NetBSD: com_ofisa_machdep.c,v 1.1.1.1 1998/05/01 21:08:55 cgd Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <dev/ofisa/ofisavar.h>
+
+#ifdef COMPAT_OLD_OFW
+
+int
+com_ofisa_md_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofisa_attach_args *aa = aux;
+ char type[8];
+ char name[8];
+ int rv;
+
+ rv = 0;
+ if (1) { /* XXX old firmware compat enabled */
+ /* match type and name properties */
+ /* At a minimum, must match type and name properties. */
+ if (OF_getprop(aa->ofp.phandle, "device_type",
+ type, sizeof(type)) > 0 &&
+ strcmp(type, "serial") == 0 &&
+ OF_getprop(aa->ofp.phandle, "name", name,
+ sizeof(name)) > 0 &&
+ strcmp(name, "serial") == 0)
+ rv = 4;
+ }
+ return (rv);
+}
+
+int
+com_ofisa_md_intr_fixup(parent, self, aux, descp, ndescs, ndescsfilled)
+ struct device *parent, *self;
+ void *aux;
+ struct ofisa_intr_desc *descp;
+ int ndescs, ndescsfilled;
+{
+
+ if (1) /* XXX old firmware compat enabled */
+ if (ndescs > 0 && ndescsfilled > 0)
+ descp[0].share = IST_LEVEL;
+ return (ndescsfilled);
+}
+
+#endif /* COMPAT_OLD_OFW */
View
88 sys/arch/arm32/ofw/lpt_ofisa_machdep.c
@@ -0,0 +1,88 @@
+/* $NetBSD: lpt_ofisa_machdep.c,v 1.1.1.1 1998/05/01 21:08:55 cgd Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <dev/ofisa/ofisavar.h>
+
+#ifdef COMPAT_OLD_OFW
+
+int
+lpt_ofisa_md_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofisa_attach_args *aa = aux;
+ char type[8];
+ char name[8];
+ int rv;
+
+ rv = 0;
+ if (1) { /* XXX old firmware compat enabled */
+ /* match type and name properties */
+ if (OF_getprop(aa->ofp.phandle, "device_type",
+ type, sizeof(type)) > 0 &&
+ strcmp(type, "parallel") == 0 &&
+ OF_getprop(aa->ofp.phandle, "name", name,
+ sizeof(name)) > 0 &&
+ strcmp(name, "parallel") == 0)
+ rv = 4;
+ }
+ return (rv);
+}
+
+int
+lpt_ofisa_md_intr_fixup(parent, self, aux, descp, ndescs, ndescsfilled)
+ struct device *parent, *self;
+ void *aux;
+ struct ofisa_intr_desc *descp;
+ int ndescs, ndescsfilled;
+{
+
+ if (1) /* XXX old firmware compat enabled */
+ if (ndescs > 0 && ndescsfilled > 0) {
+ i87307PrinterConfig(&isa_io_bs_tag, descp[0].irq);
+ descp[0].share = IST_LEVEL;
+ }
+ return (ndescsfilled);
+}
+
+#endif /* COMPAT_OLD_OFW */
View
94 sys/arch/arm32/ofw/ofisa_machdep.c
@@ -0,0 +1,94 @@
+/* $NetBSD: ofisa_machdep.c,v 1.1.1.1 1998/05/01 21:08:55 cgd Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <dev/ofisa/ofisavar.h>
+
+int
+ofisa_get_isabus_data(phandle, iba)
+ int phandle;
+ struct isabus_attach_args *iba;
+{
+
+ iba->iba_iot = &isa_io_bs_tag;
+ iba->iba_memt = &isa_io_bs_tag;
+ iba->iba_dmat = NULL;
+ iba->iba_ic = NULL;
+
+ return (0);
+}
+
+int
+ofisa_ignore_child(pphandle, cphandle)
+ int pphandle, cphandle;
+{
+
+ return (0);
+}
+
+#ifdef COMPAT_OLD_OFW
+
+int
+ofisa_md_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ char type[8];
+ char name[8];
+ int rv;
+
+ rv = 0;
+ if (1) { /* XXX old firmware compat enabled */
+ /* match type and name properties */
+ if (OF_getprop(ofp->phandle, "device_type", type,
+ sizeof(type)) > 0 &&
+ strcmp(type, "isa") == 0 &&
+ OF_getprop(ofp->phandle, "name", name,
+ sizeof(name)) > 0 &&
+ strcmp(name, "isa") == 0)
+ rv = 4;
+ }
+ return (rv);
+}
+
+#endif /* COMPAT_OLD_OFW */
View
62 sys/arch/arm32/ofw/ofisa_machdep.h
@@ -0,0 +1,62 @@
+/* $NetBSD: ofisa_machdep.h,v 1.1.1.1 1998/05/01 21:08:55 cgd Exp $ */
+
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+int ofisa_get_isabus_data __P((int, struct isabus_attach_args *));
+int ofisa_ignore_child __P((int pphandle, int cphandle));
+
+#ifdef COMPAT_OLD_OFW
+
+#define _OFISA_MD_MATCH
+int ofisa_md_match __P((struct device *, struct cfdata *, void *));
+
+#define _COM_OFISA_MD_MATCH
+#define _COM_OFISA_MD_INTR_FIXUP
+int com_ofisa_md_match __P((struct device *, struct cfdata *, void *));
+int com_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
+ struct ofisa_intr_desc *, int, int));
+
+#define _LPT_OFISA_MD_MATCH
+#define _LPT_OFISA_MD_INTR_FIXUP
+int lpt_ofisa_md_match __P((struct device *, struct cfdata *, void *));
+int lpt_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
+ struct ofisa_intr_desc *, int, int));
+
+#define _WDC_OFISA_MD_MATCH
+#define _WDC_OFISA_MD_INTR_FIXUP
+int wdc_ofisa_md_match __P((struct device *, struct cfdata *, void *));
+int wdc_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
+ struct ofisa_intr_desc *, int, int));
+
+#endif /* COMPAT_OLD_OFW */
View
131 sys/arch/arm32/ofw/ofisacs.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * OFW Glue for CS8900 Ethernet Driver
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+
+#include <machine/intr.h>
+#include <arm32/isa/isa_machdep.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <arm32/isa/if_csvar.h>
+
+
+int ofisacsprobe __P((struct device *, struct cfdata *, void *));
+void ofisacsattach __P((struct device *, struct device *, void *));
+
+
+struct cfattach ofisacs_ca = {
+ sizeof(struct device), ofisacsprobe, ofisacsattach
+};
+
+struct cfdriver ofisacs_cd = {
+ NULL, "ofisacs", DV_DULL
+};
+
+
+int
+ofisacsprobe(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ char type[64];
+ char name[64];
+ char model[64];
+ char compatible[64];
+
+ /* At a minimum, must match type and name properties. */
+ if ( OF_getprop(ofp->phandle, "device_type", type, sizeof(type)) < 0 ||
+ strcmp(type, "network") != 0 ||
+ OF_getprop(ofp->phandle, "name", name, sizeof(name)) < 0 ||
+ strcmp(name, "ethernet") != 0)
+ return 0;
+
+ /* Full match on model. */
+ if ( OF_getprop(ofp->phandle, "model", model, sizeof(model)) > 0 &&
+ strcmp(model, "CS8900") == 0)
+ return 3;
+
+ /* Check for compatible match. */
+ if ( OF_getprop(ofp->phandle, "compatible", compatible, sizeof(compatible)) > 0 &&
+ strstr(compatible, "CS8900") != NULL)
+ return 2;
+
+ /* No match. */
+ return 0;
+}
+
+
+void
+ofisacsattach(parent, dev, aux)
+ struct device *parent, *dev;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ struct isa_attach_args ia;
+
+ printf("\n");
+
+ /* XXX - Hard-wire the ISA attach args for now. -JJK */
+ ia.ia_iot = &isa_io_bs_tag;
+ ia.ia_memt = &isa_mem_bs_tag;
+ ia.ia_ic = NULL; /* not used */
+ ia.ia_iobase = 0x0300;
+ ia.ia_iosize = CS8900_IOSIZE;
+ ia.ia_irq = IRQ_ETHERNET;
+
+ if (OF_getproplen(ofp->phandle, "no-dma") < 0)
+ ia.ia_drq = 6;
+ else {
+ ia.ia_drq = DRQUNK;
+ printf("ofisacs: disabling DMA.\n");
+ }
+ ia.ia_maddr = 0xd0000;
+ ia.ia_msize = 4096;
+ ia.ia_aux = (void *)ofp->phandle;
+ ia.ia_delaybah = 0; /* don't have this! */
+
+ config_found(dev, &ia, NULL);
+}
View
127 sys/arch/arm32/ofw/ofisaess.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * OFW Glue for ES1887/ES888 Sound Driver
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+
+#include <machine/intr.h>
+#include <arm32/isa/isa_machdep.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <dev/isa/essreg.h>
+
+
+int ofisaessprobe __P((struct device *, struct cfdata *, void *));
+void ofisaessattach __P((struct device *, struct device *, void *));
+
+
+struct cfattach ofisaess_ca = {
+ sizeof(struct device), ofisaessprobe, ofisaessattach
+};
+
+struct cfdriver ofisaess_cd = {
+ NULL, "ofisaess", DV_DULL
+};
+
+
+int
+ofisaessprobe(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ char type[64];
+ char name[64];
+ char model[64];
+ char compatible[64];
+
+ /* At a minimum, must match type and name properties. */
+ if (OF_getprop(ofp->phandle, "device_type", type, sizeof(type)) < 0 ||
+ strcmp(type, "sound") != 0 ||
+ OF_getprop(ofp->phandle, "name", name, sizeof(name)) < 0 ||
+ strcmp(name, "sound") != 0)
+ return 0;
+
+ /* Full match on model. */
+ if (OF_getprop(ofp->phandle, "model", model, sizeof(model)) > 0 &&
+ (strcmp(model, "es1887-codec") == 0 ||
+ strcmp(model, "es888-codec") == 0 ||
+ strcmp(model, "ess1887-codec") == 0 ||
+ strcmp(model, "ess888-codec") == 0))
+ return 3;
+
+ /* Check for compatible match. */
+ if (OF_getprop(ofp->phandle, "compatible", compatible, sizeof(compatible)) > 0 &&
+ (strstr(compatible, "es1887-codec") != NULL ||
+ strstr(compatible, "es888-codec") != NULL ||
+ strstr(compatible, "ess1887-codec") != NULL ||
+ strstr(compatible, "ess888-codec") != NULL))
+ return 2;
+
+ /* No match. */
+ return 0;
+}
+
+
+void
+ofisaessattach(parent, dev, aux)
+ struct device *parent, *dev;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ struct isa_attach_args ia;
+
+ printf("\n");
+
+ /* XXX - Hard-wire the ISA attach args for now. -JJK */
+ ia.ia_iot = &isa_io_bs_tag;
+ ia.ia_memt = &isa_mem_bs_tag;
+ ia.ia_ic = NULL; /* not used */
+ ia.ia_iobase = 0x0220;
+ ia.ia_iosize = ESS_NPORT;
+ ia.ia_irq = IRQ_CODEC2;
+ ia.ia_drq = 5;
+ ia.ia_maddr = MADDRUNK;
+ ia.ia_msize = 0;
+ ia.ia_aux = (void *)ofp->phandle;
+ ia.ia_delaybah = 0; /* don't have this! */
+
+ config_found(dev, &ia, NULL);
+}
View
123 sys/arch/arm32/ofw/ofisapc.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * OFW Glue for PCCONS Driver
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#include <machine/intr.h>
+#include <arm32/isa/isa_machdep.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <arm32/shark/i8042reg.h>
+#include <arm32/shark/ns87307reg.h>
+
+
+int ofisapcprobe __P((struct device *, struct cfdata *, void *));
+void ofisapcattach __P((struct device *, struct device *, void *));
+
+
+struct cfattach ofisapc_ca = {
+ sizeof(struct device), ofisapcprobe, ofisapcattach
+};
+
+struct cfdriver ofisapc_cd = {
+ NULL, "ofisapc", DV_DULL
+};
+
+
+int
+ofisapcprobe(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ char type[64];
+ char name[64];
+ char model[64];
+ char compatible[64];
+
+ /* At a minimum, must match type and name properties. */
+ if ( OF_getprop(ofp->phandle, "device_type", type, sizeof(type)) < 0 ||
+ strcmp(type, "keyboard") != 0 ||
+ OF_getprop(ofp->phandle, "name", name, sizeof(name)) < 0 ||
+ strcmp(name, "keyboard") != 0)
+ return 0;
+
+ /* Better than a generic match. */
+ return 2;
+}
+
+
+void
+ofisapcattach(parent, dev, aux)
+ struct device *parent, *dev;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ static struct isa_attach_args ia;
+ bus_space_tag_t nsioIot;
+ bus_space_handle_t nsioIoh;
+
+ printf("\n");
+
+#define BASE_KEYBOARD 0x60
+
+
+ /* Start with the Keyboard and mouse device configuration in the
+ ** SuperIO H/W
+ */
+ (void)i87307KbdConfig(&isa_io_bs_tag, BASE_KEYBOARD, IRQ_KEYBOARD);
+ (void)i87307MouseConfig (&isa_io_bs_tag, IRQ_MOUSE);
+
+ /* XXX - Hard-wire the ISA attach args for now. -JJK */
+ ia.ia_iot = &isa_io_bs_tag;
+ ia.ia_memt = &isa_mem_bs_tag;
+ ia.ia_ic = NULL; /* not used */
+ ia.ia_iobase = BASE_KEYBOARD;
+ ia.ia_iosize = I8042_NPORTS;
+ ia.ia_irq = IRQ_KEYBOARD;
+ ia.ia_drq = DRQUNK;
+ ia.ia_maddr = MADDRUNK;
+ ia.ia_msize = 0;
+ ia.ia_aux = (void *)ofp->phandle;
+ ia.ia_delaybah = 0; /* don't have this! */
+
+ config_found(dev, &ia, NULL);
+
+}
View
131 sys/arch/arm32/ofw/ofisascr.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * OFW Glue for Smart Card Driver
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+
+#include <machine/intr.h>
+#include <arm32/isa/isa_machdep.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/isa/isavar.h>
+#include <arm32/shark/sequoia.h>
+
+int ofisascrprobe __P((struct device *, struct cfdata *, void *));
+void ofisascrattach __P((struct device *, struct device *, void *));
+
+
+struct cfattach ofisascr_ca = {
+ sizeof(struct device), ofisascrprobe, ofisascrattach
+};
+
+struct cfdriver ofisascr_cd = {
+ NULL, "ofisascr", DV_DULL
+};
+
+
+int
+ofisascrprobe(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ char type[64];
+ char name[64];
+ char model[64];
+ char compatible[64];
+
+
+
+
+ /* At a minimum, must match type and name properties. */
+ if ( OF_getprop(ofp->phandle, "device_type", type, sizeof(type)) < 0 ||
+ strcmp(type, "ISO7816") != 0 ||
+ OF_getprop(ofp->phandle, "name", name, sizeof(name)) < 0 ||
+ strcmp(name, "scr") != 0)
+ {
+ return 0;
+ }
+
+
+ /* Match, we dont have models yet */
+ return 2;
+
+}
+
+
+void
+ofisascrattach(parent, dev, aux)
+ struct device *parent, *dev;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ struct isa_attach_args ia;
+
+ printf("\n");
+
+ /* XXX - Hard-wire the ISA attach args for now. -JJK */
+ ia.ia_iot = &isa_io_bs_tag;
+ ia.ia_memt = &isa_mem_bs_tag;
+ ia.ia_ic = NULL; /* not used */
+ ia.ia_iobase = SEQUOIA_BASE;
+ ia.ia_iosize = SEQUOIA_NPORTS;
+ ia.ia_irq = IRQUNK;
+ ia.ia_drq = DRQUNK;
+ ia.ia_maddr = MADDRUNK;
+ ia.ia_msize = 0;
+ ia.ia_aux = (void *)ofp->phandle;
+ ia.ia_delaybah = 0; /* don't have this! */
+
+ config_found(dev, &ia, NULL);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
219 sys/arch/arm32/ofw/ofrom.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright 1998
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * XXX open for writing (for user programs to mmap, and write contents)
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <vm/vm.h>
+
+#include <machine/bus.h>
+#include <dev/ofw/openfirm.h>
+
+struct ofrom_softc {
+ struct device sc_dev;
+ int enabled;
+ vm_offset_t base;
+ vm_size_t size;
+};
+
+int ofromprobe __P((struct device *, struct cfdata *, void *));
+void ofromattach __P((struct device *, struct device *, void *));
+
+struct cfattach ofrom_ca = {
+ sizeof(struct ofrom_softc), ofromprobe, ofromattach
+};
+
+struct cfdriver ofrom_cd = {
+ NULL, "ofrom", DV_DULL
+};
+
+cdev_decl(ofrom);
+
+int
+ofromprobe(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct ofprobe *ofp = aux;
+ const char *compatible_strings[] = { "rom", NULL };
+
+ return (of_compatible(ofp->phandle, compatible_strings) == -1) ?
+ 0 : 5;
+}
+
+
+void
+ofromattach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ struct ofrom_softc *sc = (struct ofrom_softc *)self;
+ struct ofprobe *ofp = aux;
+ char regbuf[8];
+
+ if (OF_getproplen(ofp->phandle, "reg") != 8) {
+ printf(": invalid reg property\n");
+ return;
+ }
+ if (OF_getprop(ofp->phandle, "reg", regbuf, sizeof regbuf) != 8) {
+ printf(": couldn't read reg property\n");
+ return;
+ }
+ sc->base = of_decode_int(&regbuf[0]);
+ sc->size = of_decode_int(&regbuf[4]);
+ sc->enabled = 1;
+
+ printf(": 0x%x-0x%x\n", sc->base, sc->base + sc->size - 1);
+}
+
+int
+ofromopen(dev, oflags, devtype, p)
+ dev_t dev;
+ int oflags, devtype;
+ struct proc *p;
+{
+ struct ofrom_softc *sc;
+ int unit = minor(dev);
+
+ if (unit >= ofrom_cd.cd_ndevs)
+ return (ENXIO);
+ sc = ofrom_cd.cd_devs[unit];
+ if (!sc || !sc->enabled)
+ return (ENXIO);
+
+ if (oflags & FWRITE)
+ return (EINVAL);
+
+ return (0);
+}
+
+int
+ofromclose(dev, fflag, devtype, p)
+ dev_t dev;
+ int fflag, devtype;
+ struct proc *p;
+{
+
+ return (0);
+}
+
+int
+ofromrw(dev, uio, flags)
+ dev_t dev;
+ struct uio *uio;
+ int flags;
+{
+ struct ofrom_softc *sc;
+ int c, error = 0, unit = minor(dev);
+ struct iovec *iov;
+ vm_offset_t o, v;
+ extern int physlock;
+ extern char *memhook;
+
+ if (unit >= ofrom_cd.cd_ndevs)
+ return (ENXIO); /* XXX PANIC */
+ sc = ofrom_cd.cd_devs[unit];
+ if (!sc || !sc->enabled)
+ return (ENXIO); /* XXX PANIC */
+
+ /* lock against other uses of shared vmmap */
+ while (physlock > 0) {
+ physlock++;
+ error = tsleep((caddr_t)&physlock, PZERO | PCATCH, "ofromrw",
+ 0);
+ if (error)
+ return (error);
+ }
+ physlock = 1;
+
+ while (uio->uio_resid > 0 && error == 0) {
+ iov = uio->uio_iov;
+ if (iov->iov_len == 0) {
+ uio->uio_iov++;
+ uio->uio_iovcnt--;
+ if (uio->uio_iovcnt < 0)
+ panic("ofromrw");
+ continue;
+ }
+
+ /*
+ * Since everything is page aligned and no more
+ * than the rest of a page is done at once, we
+ * can just check that the offset isn't too big.
+ */
+ if (uio->uio_offset >= sc->size)
+ break;
+
+ v = sc->base + uio->uio_offset;
+ pmap_enter(pmap_kernel(), (vm_offset_t)memhook,
+ trunc_page(v), uio->uio_rw == UIO_READ ?
+ VM_PROT_READ : VM_PROT_WRITE, TRUE);
+ o = uio->uio_offset & PGOFSET;
+ c = min(uio->uio_resid, (int)(NBPG - o));
+ error = uiomove((caddr_t)memhook + o, c, uio);
+ pmap_remove(pmap_kernel(), (vm_offset_t)memhook,
+ (vm_offset_t)memhook + NBPG);
+ }
+
+ if (physlock > 1)
+ wakeup((caddr_t)&physlock);
+ physlock = 0;
+
+ return (error);
+}
+
+int
+ofrommmap(dev, off, prot)
+ dev_t dev;
+ int off, prot;
+{
+ struct ofrom_softc *sc;
+ int unit = minor(dev);
+
+ if (unit >= ofrom_cd.cd_ndevs)
+ return (-1); /* XXX PANIC */
+ sc = ofrom_cd.cd_devs[unit];
+ if (!sc || !sc->enabled)
+ return (-1); /* XXX PANIC */
+
+ if (off >= sc->size)
+ return (-1);
+
+ return arm_byte_to_page(sc->base + off);
+}
View
284 sys/arch/arm32/ofw/oftodclock.c
@@ -0,0 +1,284 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * Real time clock (RTC) functions using OFW /rtc device:
+ * inittodr()
+ * resettodr()
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/time.h>
+#include <sys/kernel.h>
+
+#include <dev/ofw/openfirm.h>
+
+/* The OFW RTC interface, straight from wmb:
+
+selftest ( -- error? )
+ Designed to be called from the "test" user interface command, e.g.
+ test /rtc
+ which displays a message if the test fails.
+ Basically all this does is to check the battery.
+
+check-battery ( -- error? )
+ Called from an open instance; returns non-zero if the battery
+ is dead. Also displays a message to that effect, which it probably
+ should not do.
+
+set-time ( s m h d m y -- )
+get-time ( -- s m h d m y )
+ Called from an open instance.
+ seconds: 0-59
+ minutes: 0-59
+ hours: 0-23
+ day: 1-31
+ month: 1-12
+ year: e.g. 1997
+
+*/
+#define OFRTC_SEC 0
+#define OFRTC_MIN 1
+#define OFRTC_HR 2
+#define OFRTC_DOM 3
+#define OFRTC_MON 4
+#define OFRTC_YR 5
+
+static int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+
+#define SECMIN ((unsigned)60) /* seconds per minute */
+#define SECHOUR ((unsigned)(60*SECMIN)) /* seconds per hour */
+#define SECDAY ((unsigned)(24*SECHOUR)) /* seconds per day */
+#define SECYR ((unsigned)(365*SECDAY)) /* seconds per common year */
+
+static int
+yeartoday(year)
+ int year;
+{
+
+ return ((year % 4) ? 365 : 366);
+}
+
+static int timeset = 0;
+
+static void
+setthetime(time_t thetime, int warning)
+{
+ timeset = 1;
+ time.tv_sec = thetime;
+ time.tv_usec = 0;
+
+ if (warning)
+ printf("WARNING: CHECK AND RESET THE DATE!\n");
+
+}
+
+static int ofrtc_phandle;
+static int ofrtc_ihandle = 0;
+static int ofrtcinited = 0;
+
+static void
+ofrtcinit()
+{
+ char buf[256];
+ int l;
+ int chosen;
+
+ if (ofrtcinited) return;
+
+ if ((ofrtc_phandle = OF_finddevice("/rtc")) == -1)
+ panic("OFW RTC: no package");
+
+ if ((l = OF_getprop(ofrtc_phandle, "device_type", buf, sizeof buf - 1)) < 0)
+ panic("OFW RTC: no device type");
+
+ if ((l >= sizeof buf) || strcmp(buf, "rtc"))
+ panic("OFW RTC: bad device type");
+
+ if ((chosen = OF_finddevice("/chosen")) == -1 ||
+ OF_getprop(chosen, "clock", &ofrtc_ihandle, sizeof(int)) < 0) {
+ ofrtc_ihandle = 0;
+ return;
+ }
+
+ ofrtc_ihandle = of_decode_int((unsigned char *)&ofrtc_ihandle);
+
+ ofrtcinited = 1;
+}
+
+static int
+ofrtcstatus()
+{
+ char status[256];
+ int l;
+
+ if ((ofrtc_ihandle == 0) ||
+ (l = OF_getprop(ofrtc_phandle, "status",
+ status, sizeof status - 1)) < 0) {
+ printf("OFW RTC: old firmware does not support RTC\n");
+ return 0;
+ }
+
+ status[sizeof status - 1] = 0; /* always null terminate */
+
+ if (strcmp(status, "okay")) { /* something is wrong */
+ printf("RTC: %s\n", status);
+ return 0;
+ }
+
+ return 1; /* all systems are go */
+
+}
+
+/*
+ * Initialize the time of day register, based on the time base which is, e.g.
+ * from a filesystem.
+ */
+void
+inittodr(base)
+ time_t base;
+{
+ time_t n;
+ int i, days = 0;
+ int date[6];
+ int yr;
+
+ /*
+ * We mostly ignore the suggested time and go for the RTC clock time
+ * stored in the CMOS RAM. If the time can't be obtained from the
+ * CMOS, or if the time obtained from the CMOS is 5 or more years
+ * less than the suggested time, we used the suggested time. (In
+ * the latter case, it's likely that the CMOS battery has died.)
+ */
+
+ if (base < 25*SECYR) { /* if before 1995, something's odd... */
+ printf("WARNING: preposterous time in file system\n");
+ /* read the system clock anyway */
+ /* happy b-day sarina */
+ base = 26*SECYR + 24*SECDAY + 18 * SECHOUR + 58 * SECMIN;
+ }
+
+ ofrtcinit();
+
+ if (!ofrtcstatus()) {
+ setthetime(base, 1);
+ return;
+ }
+
+ if (OF_call_method("get-time", ofrtc_ihandle, 0, 6,
+ date, date + 1, date + 2,
+ date + 3, date + 4, date + 5)) {
+ printf("OFW RTC: get-time failed\n");
+ setthetime(base, 1);
+ return;
+ }
+
+ n = date[OFRTC_SEC];
+ n += date[OFRTC_MIN] * SECMIN;
+ n += date[OFRTC_HR] * SECHOUR;
+ n += (date[OFRTC_DOM] - 1) * SECDAY;
+
+ yr = date[OFRTC_YR];
+
+ if (yeartoday(yr) == 366)
+ month[1] = 29;
+ for (i = date[OFRTC_MON] - 2; i >= 0; i--)
+ days += month[i];
+ month[1] = 28;
+ for (i = 1970; i < yr; i++)
+ days += yeartoday(i);
+ n += days * 3600 * 24;
+
+ n += rtc_offset * 60;
+
+ if (base < n - 5*SECYR)
+ printf("WARNING: file system time much less than clock time\n");
+
+ else if (base > n + 5*SECYR) {
+ printf("WARNING: clock time much less than file system time\n");
+ printf("WARNING: using file system time\n");
+ setthetime(base, 1);
+ return;
+ }
+
+ setthetime(n, 0);
+}
+
+/*
+ * Reset the clock.
+ */
+void
+resettodr()
+{
+ time_t n;
+ int diff, i, j;
+ int s;
+ int sec, min, hr, dom, mon, yr;
+
+ /* old version of the firmware? */
+ if (ofrtc_ihandle == 0) return;
+
+ /*
+ * We might have been called by boot() due to a crash early
+ * on. Don't reset the clock chip in this case.
+ */
+ if (!timeset)
+ return;
+
+ diff = rtc_offset * 60;
+ n = (time.tv_sec - diff) % (3600 * 24); /* hrs+mins+secs */
+ sec = n % 60;
+ n /= 60;
+ min = n % 60;
+ hr = n / 60;
+
+ n = (time.tv_sec - diff) / (3600 * 24); /* days */
+
+ for (j = 1970, i = yeartoday(j); n >= i; j++, i = yeartoday(j))
+ n -= i;
+
+ yr = j;
+
+ if (i == 366)
+ month[1] = 29;
+ for (i = 0; n >= month[i]; i++)
+ n -= month[i];
+ month[1] = 28;
+ mon = ++i;
+ dom = ++n;
+
+ if (OF_call_method("set-time", ofrtc_ihandle, 6, 0,
+ sec, min, hr, dom, mon, yr))
+ printf("OFW RTC: set-time failed\n");
+}
View
2,047 sys/arch/arm32/ofw/ofw.c
@@ -0,0 +1,2047 @@
+/*
+ * Copyright 1997
+ * Digital Equipment Corporation. All rights reserved.
+ *
+ * This software is furnished under license and may be used and
+ * copied only in accordance with the following terms and conditions.
+ * Subject to these conditions, you may download, copy, install,
+ * use, modify and distribute this software in source and/or binary
+ * form. No title or ownership is transferred hereby.
+ *
+ * 1) Any source code used, modified or distributed must reproduce
+ * and retain this copyright notice and list of conditions as
+ * they appear in the source file.
+ *
+ * 2) No right is granted to use any trade name, trademark, or logo of
+ * Digital Equipment Corporation. Neither the "Digital Equipment
+ * Corporation" name nor any trademark or logo of Digital Equipment
+ * Corporation may be used to endorse or promote products derived
+ * from this software without the prior written permission of
+ * Digital Equipment Corporation.
+ *
+ * 3) This software is provided "AS-IS" and any express or implied
+ * warranties, including but not limited to, any implied warranties
+ * of merchantability, fitness for a particular purpose, or
+ * non-infringement are disclaimed. In no event shall DIGITAL be
+ * liable for any damages whatsoever, and in particular, DIGITAL
+ * shall not be liable for special, indirect, consequential, or
+ * incidental damages or damages for lost profits, loss of
+ * revenue or loss of use, whether such damages arise in contract,
+ * negligence, tort, under statute, in equity, at law or otherwise,
+ * even if advised of the possibility of such damage.
+ */
+
+/*
+ * Routines for interfacing between NetBSD and OFW.
+ *
+ * Parts of this could be moved to an MI file in time. -JJK
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/reboot.h>
+#include <sys/callout.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/kernel.h>
+#include <sys/mbuf.h>
+#include <sys/msgbuf.h>
+#include <sys/buf.h>
+#include <sys/map.h>
+#include <sys/exec.h>
+#include <sys/mount.h>
+#include <sys/vnode.h>
+#include <sys/device.h>
+#include <vm/vm.h>
+#include <sys/sysctl.h>
+#include <sys/syscallargs.h>
+
+#ifdef SYSVMSG
+#include <sys/msg.h>
+#endif
+#ifdef SYSVSEM
+#include <sys/sem.h>
+#endif
+#ifdef SYSVSHM
+#include <sys/shm.h>
+#endif
+
+#include <dev/cons.h>
+
+#include <machine/db_machdep.h>
+#include <ddb/db_sym.h>
+#include <ddb/db_extern.h>
+
+#include <vm/vm_kern.h>
+
+#include <machine/signal.h>
+#include <machine/frame.h>
+#include <machine/bootconfig.h>
+#include <machine/cpu.h>
+#include <machine/irqhandler.h>
+#include <machine/pte.h>
+#include <machine/undefined.h>
+#include <machine/rtc.h>
+
+#include <dev/ofw/openfirm.h>
+#include <machine/ofw.h>
+
+#include <netinet/in.h>
+
+#if BOOT_FW_DHCP
+#include <nfs/bootdata.h>
+#endif
+
+#ifdef SHARK
+#include "machine/pio.h"
+#include "arm32/isa/isa_machdep.h"
+#endif
+
+#define IO_VIRT_BASE (OFW_VIRT_BASE + OFW_VIRT_SIZE)
+#define IO_VIRT_SIZE 0x01000000
+
+/*
+ * Imported constants
+ */
+/* Describe different actions to take when boot() is called */
+#define ACTION_HALT 0x01 /* Halt and boot */
+#define ACTION_REBOOT 0x02 /* Halt and request RiscBSD reboot */
+#define ACTION_KSHELL 0x04 /* Call kshell */
+#define ACTION_DUMP 0x08 /* Dump the system to the dump dev if requested */
+
+#define HALT_ACTION ACTION_HALT | ACTION_KSHELL | ACTION_DUMP /* boot(RB_HALT) */
+#define REBOOT_ACTION ACTION_REBOOT | ACTION_DUMP /* boot(0) */
+#define PANIC_ACTION ACTION_HALT | ACTION_DUMP /* panic() */
+
+
+/*
+ * Imported types
+ */
+typedef struct {
+ vm_offset_t physical;
+ vm_offset_t virtual;
+} pv_addr_t;
+
+
+/*
+ * Imported variables
+ */
+extern BootConfig bootconfig; /* temporary, I hope */
+extern int cold;
+extern int max_processes;
+
+#ifdef DIAGNOSTIC
+/* NOTE: These variables will be removed, well some of them */
+extern u_int spl_mask;
+extern u_int current_mask;
+extern int userret_count0;
+extern int userret_count1;
+#endif
+
+extern int ofw_handleticks;
+
+
+/*
+ * Imported routines
+ */
+extern void map_section __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
+extern void map_pagetable __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
+extern void map_entry __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
+extern void map_entry_ro __P((vm_offset_t pt, vm_offset_t va, vm_offset_t pa));
+extern void pmap_bootstrap __P((vm_offset_t kernel_l1pt, pt_entry_t kernel_ptpt));
+extern void dump_spl_masks __P((void));
+extern void dumpsys __P((void));
+extern void dotickgrovelling __P((vm_offset_t));
+extern char *strstr __P((char *s1, char *s2));
+
+#define WriteWord(a, b) \
+*((volatile unsigned int *)(a)) = (b)
+
+#define ReadWord(a) \
+(*((volatile unsigned int *)(a)))
+
+
+/*
+ * Exported variables
+ */
+/* These should all be in a meminfo structure. */
+vm_offset_t physical_start;
+vm_offset_t physical_freestart;
+vm_offset_t physical_freeend;
+vm_offset_t physical_end;
+int physical_memoryblock;
+u_int free_pages;
+int physmem;
+pv_addr_t systempage;
+#ifndef OFWGENCFG
+pv_addr_t irqstack;
+#endif
+pv_addr_t undstack;
+pv_addr_t abtstack;
+pv_addr_t kernelstack;
+
+vm_offset_t pagetables_start;
+vm_offset_t msgbufphys;
+
+/* for storage allocation, used to be local to ofw_construct_proc0_addrspace */
+static vm_offset_t virt_freeptr;
+
+int ofw_callbacks = 0; /* debugging counter */
+
+/**************************************************************/
+
+
+/*
+ * Declarations and definitions private to this module
+ *
+ */
+
+struct mem_region {
+ vm_offset_t start;
+ vm_size_t size;
+};
+
+struct mem_translation {
+ vm_offset_t virt;
+ vm_size_t size;
+ vm_offset_t phys;
+ unsigned int mode;
+};
+
+struct isa_range {
+ vm_offset_t isa_phys_hi;
+ vm_offset_t isa_phys_lo;
+ vm_offset_t parent_phys_start;
+ vm_size_t isa_size;
+};
+
+struct vl_range {
+ vm_offset_t vl_phys_hi;
+ vm_offset_t vl_phys_lo;
+ vm_offset_t parent_phys_start;
+ vm_size_t vl_size;
+};
+
+struct vl_isa_range {
+ vm_offset_t isa_phys_hi;
+ vm_offset_t isa_phys_lo;
+ vm_offset_t parent_phys_hi;
+ vm_offset_t parent_phys_lo;
+ vm_size_t isa_size;
+};
+
+struct dma_range {
+ vm_offset_t start;
+ vm_size_t size;
+};
+
+struct ofw_cbargs {
+ char *name;
+ int nargs;
+ int nreturns;
+ int args_n_results[12];
+};
+
+
+/* Memory info */
+static int nOFphysmem;
+static struct mem_region *OFphysmem;
+static int nOFphysavail;
+static struct mem_region *OFphysavail;
+static int nOFtranslations;
+static struct mem_translation *OFtranslations;
+static int nOFdmaranges;
+static struct dma_range *OFdmaranges;
+
+/* The OFW client services handle. */
+/* Initialized by ofw_init(). */
+static ofw_handle_t ofw_client_services_handle;
+
+
+static void ofw_callbackhandler(struct ofw_cbargs *);
+static void ofw_construct_proc0_addrspace __P((vm_offset_t *, vm_offset_t *));
+static void ofw_getphysmeminfo __P((void));
+static void ofw_getvirttranslations __P((void));
+static void *ofw_malloc(vm_size_t size);
+static void ofw_claimpages __P((vm_offset_t *, pv_addr_t *, vm_size_t));
+static void ofw_discardmappings __P ((vm_offset_t, vm_offset_t, vm_size_t));
+static int ofw_mem_ihandle __P((void));
+static int ofw_mmu_ihandle __P((void));
+static vm_offset_t ofw_claimphys __P((vm_offset_t, vm_size_t, vm_offset_t));
+static vm_offset_t ofw_releasephys __P((vm_offset_t, vm_size_t));
+static vm_offset_t ofw_claimvirt __P((vm_offset_t, vm_size_t, vm_offset_t));
+static void ofw_settranslation __P ((vm_offset_t, vm_offset_t, vm_size_t, int));
+static void ofw_initallocator(void);
+static void ofw_configisaonly(vm_offset_t *, vm_offset_t *);
+static void ofw_configvl(int, vm_offset_t *, vm_offset_t *);
+static vm_offset_t ofw_valloc(vm_offset_t, vm_offset_t);
+
+
+/*
+ * DHCP hooks. For a first cut, we look to see if there is a DHCP
+ * packet that was saved by the firmware. If not, we proceed as before,
+ * getting hand-configured data from NVRAM. If there is one, we get the
+ * packet, and extract the data from it. For now, we hand that data up
+ * in the boot_args string as before.
+ */
+
+
+/**************************************************************/
+
+
+/*
+ *
+ * Support routines for xxx_machdep.c
+ *
+ * The intent is that all OFW-based configurations use the
+ * exported routines in this file to do their business. If
+ * they need to override some function they are free to do so.
+ *
+ * The exported routines are:
+ *
+ * openfirmware
+ * ofw_init
+ * ofw_boot
+ * ofw_getbootinfo
+ * ofw_configmem
+ * ofw_configisa
+ * ofw_configisadma
+ * ofw_gettranslation
+ * ofw_map
+ * ofw_getcleaninfo
+ */
+
+
+int
+openfirmware(args)
+ void *args;
+{
+ int ofw_result;
+ u_int saved_irq_state;
+
+ /* OFW is not re-entrant, so we wrap a mutex around the call. */
+ saved_irq_state = disable_interrupts(I32_bit);
+ ofw_result = ofw_client_services_handle(args);
+ (void)restore_interrupts(saved_irq_state);
+
+ return(ofw_result);
+}
+
+
+void
+ofw_init(ofw_handle)
+ ofw_handle_t ofw_handle;
+{
+ ofw_client_services_handle = ofw_handle;
+
+ /* Everything we allocate in the remainder of this block is
+ * constrained to be in the "kernel-static" portion of the
+ * virtual address space (i.e., 0xF0000000 - 0xF1000000).
+ * This is because all such objects are expected to be in
+ * that range by NetBSD, or the objects will be re-mapped
+ * after the page-table-switch to other specific locations.
+ * In the latter case, it's simplest if our pre-switch handles
+ * on those objects are in regions that are already "well-
+ * known." (Otherwise, the cloning of the OFW-managed address-
+ * space becomes more awkward.) To minimize the number of L2
+ * page tables that we use, we are further restricting the
+ * remaining allocations in this block to the bottom quarter of
+ * the legal range. OFW will have loaded the kernel text+data+bss
+ * starting at the bottom of the range, and we will allocate
+ * objects from the top, moving downwards. The two sub-regions
+ * will collide if their total sizes hit 4MB. The current total
+ * is <1.5MB, so we aren't in any real danger yet. The variable
+ * virt-freeptr represents the next free va (moving downwards).
+ */
+ virt_freeptr = KERNEL_BASE + 0x00400000;
+}
+
+
+void
+ofw_boot(howto, bootstr)
+ int howto;
+ char *bootstr;
+{
+ int loop;
+ int action;
+
+#ifdef DIAGNOSTIC
+ if (curproc == NULL)
+ printf("curproc = 0 - must have been in cpu_idle()\n");
+/* if (curpcb)
+ printf("curpcb=%08x pcb_sp=%08x pcb_und_sp=%08x\n", curpcb, curpcb->pcb_sp, curpcb->pcb_und_sp);*/
+ printf("userret_count0=%d\n", userret_count0);
+ printf("userret_count1=%d\n", userret_count1);
+
+ printf("boot: howto=%08x %08x curproc=%08x\n", howto, spl_mask, (u_int)curproc);
+
+ printf("current_mask=%08x spl_mask=%08x\n", current_mask, spl_mask);
+ printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_clock=%08x ipl_imp=%08x\n",
+ irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY],
+ irqmasks[IPL_CLOCK], irqmasks[IPL_IMP]);
+
+ dump_spl_masks();
+#endif
+
+ /* If we are still cold then hit the air brakes and crash to earth fast */
+ if (cold) {
+ doshutdownhooks();
+ printf("Halted while still in the ICE age.\n");
+ goto ofw_exit;
+ }
+
+ /*
+ * Depending on how we got here and with what intructions, choose
+ * the actions to take. (See the actions defined above)
+ */
+ if (panicstr)
+ action = PANIC_ACTION;
+ else if (howto & RB_HALT)
+ action = HALT_ACTION;
+ else
+ action = REBOOT_ACTION;
+
+ /*
+ * If RB_NOSYNC was not specified sync the discs.
+ * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
+ * It looks like syslogd is getting woken up only to find that it cannot
+ * page part of the binary in as the filesystem has been unmounted.
+ */
+ if (!(howto & RB_NOSYNC))
+ bootsync();
+
+ /* Say NO to interrupts */
+ splhigh();
+
+ /* If we need to do a dump, do it */
+ if ((howto & RB_DUMP) && (action & ACTION_DUMP)) {
+ dumpsys();
+ }
+
+ /* Run any shutdown hooks */
+ printf("Running shutdown hooks ...\n");
+ doshutdownhooks();
+
+ /* Make sure IRQ's are disabled */
+ IRQdisable;
+
+ if (action & ACTION_HALT)
+ goto ofw_exit;
+
+ /* Tell the user we are booting */
+ printf("boot...");
+
+ /* Give the user time to read the last couple of lines of text. */
+ for (loop = 5; loop > 0; --loop) {
+ printf("%d..", loop);
+ delay(500000);
+ }
+
+ /* Jump into the OFW boot routine. */
+ {
+ static char str[256];
+ char *ap = str, *ap1 = ap;
+
+ if (bootstr && *bootstr) {
+ if (strlen(bootstr) > sizeof str - 5)
+ printf("boot string too large, ignored\n");
+ else {
+ strcpy(str, bootstr);
+ ap1 = ap = str + strlen(str);
+ *ap++ = ' ';
+ }
+ }
+ *ap++ = '-';
+ if (howto & RB_SINGLE)
+ *ap++ = 's';
+ if (howto & RB_KDB)
+ *ap++ = 'd';
+ *ap++ = 0;
+ if (ap[-2] == '-')
+ *ap1 = 0;
+#ifdef SHARK
+ shark_screen_cleanup(0);
+#endif
+ OF_boot(str);
+
+ /* Not reached. */
+ }
+
+ofw_exit:
+ printf("Calling OF_exit...\n");
+#ifdef SHARK
+ shark_screen_cleanup(1);
+#endif
+ OF_exit();
+ /* Not reached. */
+}
+
+
+#if BOOT_FW_DHCP
+
+extern char *ip2dotted __P((struct in_addr));
+
+/*
+ * Get DHCP data from OFW
+ */
+
+void
+get_fw_dhcp_data(struct bootdata *bdp) {
+ int chosen;
+ int dhcplen;
+
+ bzero((char *)bdp, sizeof(*bdp));
+ if ((chosen = OF_finddevice("/chosen")) == -1)
+ panic("no /chosen from OFW");
+ if ((dhcplen = OF_getproplen(chosen, "bootp-response")) > 0) {
+ u_char *cp;
+ int dhcp_type = 0;
+ char *ip;
+
+ /*
+ * OFW saved a DHCP (or BOOTP) packet for us.
+ */
+ if(dhcplen > sizeof(bdp->dhcp_packet))
+ panic("DHCP packet too large");
+ OF_getprop(chosen, "bootp-response", &bdp->dhcp_packet,
+ sizeof(bdp->dhcp_packet));
+ SANITY(bdp->dhcp_packet.op == BOOTREPLY, "bogus DHCP packet");
+ /*
+ * Collect the interesting data from DHCP into
+ * the bootdata structure.
+ */
+ bdp->ip_address = bdp->dhcp_packet.yiaddr;
+ ip = ip2dotted(bdp->ip_address);
+ if(bcmp(bdp->dhcp_packet.options, DHCP_OPTIONS_COOKIE, 4) == 0)
+ parse_dhcp_options(
+ &bdp->dhcp_packet,
+ bdp->dhcp_packet.options + 4,
+ &bdp->dhcp_packet.options[dhcplen - DHCP_FIXED_NON_UDP],
+ bdp,
+ ip
+ );
+ if (bdp->root_ip.s_addr == 0)
+ bdp->root_ip = bdp->dhcp_packet.siaddr;
+ if (bdp->swap_ip.s_addr == 0)
+ bdp->swap_ip = bdp->dhcp_packet.siaddr;
+ }
+ /*
+ * If the DHCP packet did not contain all the necessary data,
+ * look in NVRAM for the missing parts.
+ */
+ {
+ int options;
+ int proplen;
+# define BOOTJUNKV_SIZE 256
+ char bootjunkv[BOOTJUNKV_SIZE]; /* minimize stack usage */
+
+
+ if ((options = OF_finddevice("/options")) == -1)
+ panic("can't find /options");
+ if (bdp->ip_address.s_addr == 0 &&
+ (proplen = OF_getprop(options, "ipaddr",
+ bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
+ bootjunkv[proplen] = '\0';
+ if (dotted2ip(bootjunkv, &bdp->ip_address.s_addr) == 0)
+ bdp->ip_address.s_addr = 0;
+ }
+ if (bdp->ip_mask.s_addr == 0 &&
+ (proplen = OF_getprop(options, "netmask",
+ bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
+ bootjunkv[proplen] = '\0';
+ if (dotted2ip(bootjunkv, &bdp->ip_mask.s_addr) == 0)
+ bdp->ip_mask.s_addr = 0;
+ }
+ if (bdp->hostname[0] == '\0' &&
+ (proplen = OF_getprop(options, "hostname",
+ bdp->hostname, sizeof(bdp->hostname) - 1)) > 0) {
+ bdp->hostname[proplen] = '\0';
+ }
+ if (bdp->root[0] == '\0' &&
+ (proplen = OF_getprop(options, "rootfs",
+ bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
+ bootjunkv[proplen] = '\0';
+ parse_server_path(bootjunkv, &bdp->root_ip, bdp->root);
+ }
+ if (bdp->swap[0] == '\0' &&
+ (proplen = OF_getprop(options, "swapfs",
+ bootjunkv, BOOTJUNKV_SIZE - 1)) > 0) {
+ bootjunkv[proplen] = '\0';
+ parse_server_path(bootjunkv, &bdp->swap_ip, bdp->swap);
+ }
+ }
+}
+
+#endif /* BOOT_FW_DHCP */
+
+void
+ofw_getbootinfo(bp_pp, ba_pp)
+ char **bp_pp;
+ char **ba_pp;
+{
+ int chosen;
+ int bp_len;
+ int ba_len;
+ char *bootpathv;
+ char *bootargsv;
+
+ /* Read the bootpath and bootargs out of OFW. */
+ /* XXX is bootpath still interesting? --emg */
+ if ((chosen = OF_finddevice("/chosen")) == -1)
+ panic("no /chosen from OFW");
+ bp_len = OF_getproplen(chosen, "bootpath");
+ ba_len = OF_getproplen(chosen, "bootargs");
+ if (bp_len < 0 || ba_len < 0)
+ panic("can't get boot data from OFW");
+
+ bootpathv = (char *)ofw_malloc(bp_len);
+ bootargsv = (char *)ofw_malloc(ba_len);
+
+ if (bp_len)
+ OF_getprop(chosen, "bootpath", bootpathv, bp_len);
+ else
+ bootpathv[0] = '\0';
+
+ if (ba_len)
+ OF_getprop(chosen, "bootargs", bootargsv, ba_len);
+ else
+ bootargsv[0] = '\0';
+
+ *bp_pp = bootpathv;
+ *ba_pp = bootargsv;
+}
+
+vm_offset_t
+ofw_getcleaninfo()
+{
+ int cpu;
+ vm_offset_t vclean, pclean;
+
+ if ((cpu = OF_finddevice("/cpu")) == -1)
+ panic("no /cpu from OFW");
+
+ if ((OF_getprop(cpu, "d-cache-flush-address", &vclean,
+ sizeof(vclean))) != sizeof(vclean)) {
+#ifdef DEBUG
+ printf("no OFW d-cache-flush-address property\n");
+#endif
+ return -1;
+ }
+
+ if ((pclean = ofw_gettranslation(of_decode_int((unsigned char *)&vclean)))
+ == -1)
+ panic("OFW failed to translate cache flush address");
+
+ return pclean;
+}
+
+/* hack, hack, hack, your DMA,
+ gently into the kernel.
+ merrily, merrily, merrily, merrily,
+ life is just a gerbil.
+
+ Notes:
+ - Assumes that align is a power of 2.
+ - OFW integer properties stored in network order (thanks, Mitch).
+*/
+vm_offset_t ofw_getisadmamemory(size, align)
+ vm_size_t size;
+ vm_offset_t align;
+{
+ int nphysavail;
+ struct mem_region *physavail;
+ int phandle;
+ int avail_len;
+ int region;
+ vm_offset_t physstart, physstartal;
+ vm_size_t physsize, physsizeal;
+
+#ifdef DEBUG
+ printf("getisadmamemory: %08x, %08x\n", size, align);
+#endif
+
+ /* the memory allocated by this ofw_malloc will be lost. sue me. */
+
+ if (((phandle = OF_finddevice("/memory")) == -1) ||
+ (avail_len = OF_getproplen(phandle, "available")) <= 0 ||
+ (physavail = ofw_malloc(avail_len)) == 0 ||
+ OF_getprop(phandle, "available", physavail, avail_len) != avail_len) {
+ panic("ofw_getisadmamemory: get available memory failed");
+ }
+
+ nphysavail = avail_len / sizeof(struct mem_region);
+
+ for (region = 0; region < nphysavail; ++region) {
+ physsize = of_decode_int((unsigned char *)&physavail[region].size);
+ physstart = of_decode_int((unsigned char *)&physavail[region].start);
+#ifdef DEBUG
+ printf("avail: %08x %08x\n", physstart, physsize);
+#endif
+ /* do alignment now */
+ physstartal = ((physstart + (align - 1)) & ~(align - 1));
+ if ((physstartal - physstart) > physsize)
+ physsizeal = 0;
+ else
+ physsizeal = physsize - (physstartal - physstart);
+#ifdef DEBUG
+ printf("aligned: %08x %08x\n", physstartal, physsizeal);
+#endif
+ if ((size <= physsizeal) &&
+ /* same function that's called by isadma.c: */
+ !isa_machdep_dmarangecheck(physstartal, size)) {
+ /* we have a winner */
+#ifdef DEBUG
+ printf("we have a winner: %08x %08x\n", physstartal, size);
+#endif
+ if (ofw_claimphys(physstartal, size, 0) == -1)
+ panic("ofw_getisadmamemory: get claim memory failed");
+
+ return physstartal;
+ }
+ }
+
+ return -1; /* uh, oh. */
+}
+
+void
+ofw_configisa(vm_offset_t *pio, vm_offset_t *pmem)
+{
+ int vl;
+
+ if ((vl = OF_finddevice("/vlbus")) == -1) /* old style OFW dev info tree */
+ ofw_configisaonly(pio, pmem);
+ else /* old style OFW dev info tree */
+ ofw_configvl(vl, pio, pmem);
+}
+
+static void
+ofw_configisaonly(vm_offset_t *pio, vm_offset_t *pmem)
+{
+ int isa;
+ int rangeidx;
+ int size;
+ vm_offset_t hi, start;
+ struct isa_range ranges[2];
+
+ if ((isa = OF_finddevice("/isa")) == -1)
+ panic("OFW has no /isa device node");
+
+ /* expect to find two isa ranges: IO/data and memory/data */
+ if ((size = OF_getprop(isa, "ranges", ranges, sizeof(ranges)))
+ != sizeof(ranges))
+ panic("unexpected size of OFW /isa ranges property: %d", size);
+
+ *pio = *pmem = -1;
+
+ for (rangeidx = 0; rangeidx < 2; ++rangeidx) {
+ hi = of_decode_int((unsigned char *)&ranges[rangeidx].isa_phys_hi);
+ start = of_decode_int((unsigned char *)
+ &ranges[rangeidx].parent_phys_start);
+
+ if (hi & 1) { /* then I/O space */
+ *pio = start;
+ } else {
+ *pmem = start;
+ }
+ } /* END for */
+
+ if ((*pio == -1) || (*pmem == -1))
+ panic("bad OFW /isa ranges property");
+
+}
+
+static void
+ofw_configvl(int vl, vm_offset_t *pio, vm_offset_t *pmem)
+{
+ int isa;
+ int ir, vr;
+ int size;
+ vm_offset_t hi, start;
+ struct vl_isa_range isa_ranges[2];
+ struct vl_range vl_ranges[2];
+
+ if ((isa = OF_finddevice("/vlbus/isa")) == -1)
+ panic("OFW has no /vlbus/isa device node");
+
+ /* expect to find two isa ranges: IO/data and memory/data */
+ if ((size = OF_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges)))
+ != sizeof(isa_ranges))
+ panic("unexpected size of OFW /vlbus/isa ranges property: %d", size);
+
+ /* expect to find two vl ranges: IO/data and memory/data */
+ if ((size = OF_getprop(vl, "ranges", vl_ranges, sizeof(vl_ranges)))
+ != sizeof(vl_ranges))
+ panic("unexpected size of OFW /vlbus ranges property: %d", size);
+
+ *pio = -1;
+ *pmem = -1;
+
+ for (ir = 0; ir < 2; ++ir) {
+ for (vr = 0; vr < 2; ++vr) {
+ if ((isa_ranges[ir].parent_phys_hi == vl_ranges[vr].vl_phys_hi) &&
+ (isa_ranges[ir].parent_phys_lo == vl_ranges[vr].vl_phys_lo)) {
+ hi = of_decode_int((unsigned char *)&isa_ranges[ir].isa_phys_hi);
+ start = of_decode_int((unsigned char *)
+ &vl_ranges[vr].parent_phys_start);
+
+ if (hi & 1) { /* then I/O space */
+ *pio = start;
+ } else {
+ *pmem = start;
+ }
+ } /* END if */
+ } /* END for */
+ } /* END for */
+
+ if ((*pio == -1) || (*pmem == -1))
+ panic("bad OFW /isa ranges property");
+
+}
+
+void
+ofw_configisadma(vm_offset_t *pdma)
+{
+ int root;
+ int rangeidx;
+ int size;
+ struct dma_range *dr;
+
+ if ((root = OF_finddevice("/")) == -1 ||
+ (size = OF_getproplen(root, "dma-ranges")) <= 0 ||
+ (OFdmaranges = (struct dma_range *)ofw_malloc(size)) == 0 ||
+ OF_getprop(root, "dma-ranges", OFdmaranges, size) != size)
+ panic("bad / dma-ranges property");
+
+ nOFdmaranges = size / sizeof(struct dma_range);
+
+ for (rangeidx = 0, dr = OFdmaranges;
+ rangeidx < nOFdmaranges;
+ ++rangeidx, ++dr) {
+ dr->start = of_decode_int((unsigned char *)&dr->start);
+ dr->size = of_decode_int((unsigned char *)&dr->size);
+ }
+
+#ifdef DEBUG
+ printf("dma ranges size = %d\n", size);
+
+ for (rangeidx = 0; rangeidx < nOFdmaranges; ++rangeidx) {
+ printf("%08x %08x\n",
+ OFdmaranges[rangeidx].start,
+ OFdmaranges[rangeidx].size);
+ }
+#endif
+
+ /* XXX - Snarf physical memory for DMA bounce buffers. */
+
+ if ((*pdma =
+ ofw_getisadmamemory(DMA_BOUNCE * NBPG, DMA_BOUNCE * NBPG)) == -1)
+ panic("no ISA DMA memory: is memory populated in the correct slot?");
+}
+
+int
+ofw_isadmarangeintersect(vm_offset_t pa, vm_offset_t size,
+ vm_offset_t *ppa, vm_offset_t *psize)
+{
+ int rangeidx;
+ struct dma_range *dr;
+
+ for (rangeidx = 0, dr = OFdmaranges;
+ rangeidx < nOFdmaranges;
+ ++rangeidx, ++dr) {
+ if ((dr->start <= pa) && (pa < (dr->start + dr->size))) {
+ *ppa = pa;
+ *psize = min(pa + size, dr->start + dr->size) - pa;
+ return 1; /* intersection is not NULL */
+ } else if ((pa < dr->start) && (dr->start < (pa + size))) {
+ *ppa = dr->start;
+ *psize = min((pa + size) - dr->start, dr->size);
+ return 1; /* intersection is not NULL */
+ }
+ }
+
+ return 0; /* intersection is NULL */
+}
+
+/*
+ * Memory configuration:
+ *
+ * We start off running in the environment provided by OFW.
+ * This has the MMU turned on, the kernel code and data
+ * mapped-in at KERNEL_BASE (0xF0000000), OFW's text and
+ * data mapped-in at OFW_VIRT_BASE (0xF7000000), and (possibly)
+ * page0 mapped-in at 0x0.
+ *
+ * The strategy is to set-up the address space for proc0 --
+ * including the allocation of space for new page tables -- while
+ * memory is still managed by OFW. We then effectively create a
+ * copy of the address space by dumping all of OFW's translations
+ * and poking them into the new page tables. We then notify OFW
+ * that we are assuming control of memory-management by installing
+ * our callback-handler, and switch to the NetBSD-managed page
+ * tables with the setttb() call.
+ *
+ * This scheme may cause some amount of memory to be wasted within
+ * OFW as dead page tables, but it shouldn't be more than about
+ * 20-30KB. (It's also possible that OFW will re-use the space.)
+ */
+void
+ofw_configmem(void)
+{
+ vm_offset_t proc0_ttbbase;
+ vm_offset_t proc0_ptpt;
+
+ /* XXX - Snarf physical memory for max_processes L1 pagetables. */
+ /* I hate that these are statically-allocated; it needs to be */
+ /* fixed soon! -JJK */
+ pagetables_start = ofw_claimphys(0, PD_SIZE * max_processes, PD_SIZE);
+ if (pagetables_start == -1)
+ panic("unable to allocate L1 pagetables");
+
+ /* Set-up proc0 address space. */
+ ofw_construct_proc0_addrspace(&proc0_ttbbase, &proc0_ptpt);
+
+ /* Get a dump of OFW's picture of physical memory. */
+ /* This is used below to initialize a load of variables used by pmap. */
+ /* We get it now rather than later because we are about to */
+ /* tell OFW to stop managing memory. */
+ ofw_getphysmeminfo();
+
+ /* We are about to take control of memory-management from OFW. */
+ /* Establish callbacks for OFW to use for its future memory needs. */
+ /* This is required for us to keep using OFW services. */
+ {
+ /* First initialize our callback memory allocator. */
+ ofw_initallocator();
+
+ OF_set_callback((void(*)())ofw_callbackhandler);
+ }
+
+ /* Switch to the proc0 pagetables. */
+ setttb(proc0_ttbbase);
+
+ /* Aaaaaaaah, running in the proc0 address space! */
+ /* I feel good... */
+
+ /* Set-up the various globals which describe physical memory for pmap. */
+ {
+ struct mem_region *mp;
+ int totalcnt;
+ int availcnt;
+ int i;
+
+ /* physmem, physical_start, physical_end, physical_memoryblock */
+ physmem = 0;
+ for (totalcnt = 0, mp = OFphysmem;
+ totalcnt < nOFphysmem;
+ totalcnt++, mp++) {
+#ifdef OLDPRINTFS
+ printf("physmem: %x, %x\n", mp->start, mp->size);
+#endif
+ physmem += btoc(mp->size);
+ }
+ physical_start = OFphysmem[0].start;
+ mp--;
+ physical_end = mp->start + mp->size;
+ physical_memoryblock = 0;
+
+ /* free_pages, physical_freestart, physical_freeend */
+ free_pages = 0;
+ for (availcnt = 0, mp = OFphysavail;
+ availcnt < nOFphysavail;
+ availcnt++, mp++) {
+#ifdef OLDPRINTFS
+ printf("physavail: %x, %x\n", mp->start, mp->size);
+#endif
+ free_pages += btoc(mp->size);
+ }
+ physical_freestart = OFphysavail[0].start;
+ mp--;
+ physical_freeend = mp->start + mp->size;
+#ifdef OLDPRINTFS
+ printf("pmap_bootstrap: physmem = %x, free_pages = %x\n", physmem, free_pages);
+#endif
+
+ /*
+ * This is a hack to work with the existing pmap code.
+ * That code depends on a RiscPC BootConfig structure
+ * containing, among other things, an array describing
+ * the regions of physical memory. So, for now, we need
+ * to stuff our OFW-derived physical memory info into a
+ * "fake" BootConfig structure.
+ *
+ * An added twist is that we initialize the BootConfig
+ * structure with our "available" physical memory regions
+ * rather than the "total" physical memory regions. Why?
+ * Because:
+ *
+ * (a) the VM code requires that the "free" pages it is
+ * initialized with have consecutive indices. This
+ * allows it to use more efficient data structures
+ * (presumably).
+ * (b) the current pmap routines which report the initial
+ * set of free page indices (pmap_next_page) and
+ * which map addresses to indices (pmap_page_index)
+ * assume that the free pages are consecutive across
+ * memory region boundaries.
+ *
+ * This means that memory which is "stolen" at startup time
+ * (say, for page descriptors) MUST come from either the
+ * bottom of the first region or the top of the last.
+ *
+ * This requirement doesn't mesh well with OFW (or at least
+ * our use of it). We can get around it for the time being
+ * by pretending that our "available" region array describes
+ * all of our physical memory. This may cause some important
+ * information to be excluded from a dump file, but so far
+ * I haven't come across any other negative effects.
+ *
+ * In the long-run we should fix the index generation/translation
+ * code in the pmap module.
+ */
+
+ if (DRAM_BLOCKS < (availcnt + 1))
+ panic("more ofw memory regions than bootconfig blocks");
+
+ for (i = 0, mp = OFphysavail; i < nOFphysavail; i++, mp++) {
+ bootconfig.dram[i].address = mp->start;
+ bootconfig.dram[i].pages = btoc(mp->size);
+ }
+ bootconfig.dramblocks = availcnt;
+ }
+
+ /* Initialize pmap module. */
+ pmap_bootstrap(PAGE_DIRS_BASE, proc0_ptpt);
+ cpu_cache_syncI(); /* XXX - Is this really needed */
+}
+
+
+/*
+ ************************************************************
+
+ Routines private to this module
+
+ ************************************************************
+ */
+
+/* N.B. Not supposed to call printf in callback-handler! Could deadlock! */
+static void
+ofw_callbackhandler(args)
+ struct ofw_cbargs *args;
+{
+ char *name = args->name;
+ int nargs = args->nargs;
+ int nreturns = args->nreturns;