Port-x68k archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

purge x68k_config_found()



Please review the following patch.

I purge x68k_config_found() on config_console() in
sys/arch/x68k/x68k/autoconf.c to simplify consinit routine
in x68k.  And it is used to split device_t/softc of the
rest of devices in the next step.

Before this patch, config_console() tracks special device
tree like mainbus -> grfbus -> grf -> ite and
mainbus -> intio -> mfp to only initialize grf, ite, mfp.
It is difficult to understand.  And then, x68k_config_found()
emulates 'struct device'.  It is not a good way.

In this patch, config_console() does not track the tree but
calls each initialization function directly. For example,
initalizing mfp part is mfp_config_console().  I think
it's easy way, easy to read.

Are there any comments?
I'll commit it one or two weeks later, if there are no comments.
---
Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>

Index: sys/arch/x68k/dev/grf_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/grf_machdep.c,v
retrieving revision 1.27
diff -u -r1.27 grf_machdep.c
--- sys/arch/x68k/dev/grf_machdep.c     4 Mar 2007 06:01:06 -0000       1.27
+++ sys/arch/x68k/dev/grf_machdep.c     31 Dec 2008 13:39:47 -0000
@@ -90,17 +90,11 @@
 #include <sys/systm.h>
 #include <sys/device.h>
 
+#include <machine/autoconf.h>
 #include <machine/grfioctl.h>
 #include <x68k/dev/grfvar.h>
 #include <x68k/x68k/iodevice.h>
 
-/*
- * false when initing for the console.
- */
-extern int x68k_realconfig;
-extern int x68k_config_found(struct cfdata *, struct device *,
-                            void *, cfprint_t);
-
 /* grfbus: is this necessary? */
 int grfbusprint(void *auxp, const char *);
 int grfbusmatch(struct device *, struct cfdata *, void *);
@@ -120,12 +114,6 @@
 CFATTACH_DECL(grf, sizeof(struct grf_softc),
     grfmatch, grfattach, NULL, NULL);
 
-/*
- * only used in console init.
- */
-static struct cfdata *cfdata_gbus;
-static struct cfdata *cfdata_grf;
-
 extern struct cfdriver grfbus_cd;
 
 int
@@ -134,30 +122,15 @@
        if (strcmp(auxp, grfbus_cd.cd_name))
                return (0);
 
-       if ((x68k_realconfig == 0) || (cfdata_gbus == NULL)) {
-
-               /*
-                * Probe layers we depend on
-                */
-               if (x68k_realconfig == 0) {
-                       cfdata_gbus = cfp;
-               }
-       }
        return (1);
 }
 
 void
 grfbusattach(struct device *pdp, struct device *dp, void *auxp)
 {
-       int i;
 
-       if (dp == NULL) {
-               i = 0;
-               x68k_config_found(cfdata_gbus, NULL, &i, grfbusprint);
-       } else {
-               printf("\n");
-               config_search_ia(grfbussearch, dp, "grfb", NULL);
-       }
+       printf("\n");
+       config_search_ia(grfbussearch, dp, "grfb", NULL);
 }
 
 int
@@ -187,19 +160,13 @@
        int addr;
 
        addr = cfp->cf_loc[GRFBCF_ADDR];
-       if (x68k_realconfig == 0) {
-               if (addr != 0)
-                       return 0;
-               cfdata_grf = cfp;
-       }
-
        if (addr < 0 || addr > ngrfsw)
                return 0;
 
        return 1;
 }
 
-static struct grf_softc        congrf;
+struct grf_softc congrf;
 
 void
 grfattach(struct device *parent, struct device *dp, void *aux)
@@ -208,16 +175,6 @@
        struct cfdata *cf;
        int addr;
 
-       /*
-        * Handle exeption case: early console init
-        */
-       if (dp == NULL) {
-               /* Attach console ite */
-               grfinit(&congrf, 0);
-               x68k_config_found(cfdata_grf, NULL, &congrf, grfprint);
-               return;
-       }
-
        cf = device_cfdata(dp);
        addr = cf->cf_loc[GRFBCF_ADDR];
        grfinit(dp, addr);
@@ -268,3 +225,9 @@
 
        return 0;
 }
+
+void
+grf_config_console(void)
+{
+       grfinit(&congrf, 0);
+}
Index: sys/arch/x68k/dev/intio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/intio.c,v
retrieving revision 1.38
diff -u -r1.38 intio.c
--- sys/arch/x68k/dev/intio.c   18 Dec 2008 05:56:42 -0000      1.38
+++ sys/arch/x68k/dev/intio.c   31 Dec 2008 13:39:48 -0000
@@ -134,11 +134,6 @@
        struct evcnt            *iiv_evcnt;
 } iiv[256] = {{0,},};
 
-/* used in console initialization */
-extern int x68k_realconfig;
-int x68k_config_found(struct cfdata *, struct device *, void *, cfprint_t);
-static cfdata_t cfdata_intiobus = NULL;
-
 #ifdef DEBUG
 int intio_debug = 0;
 #endif
@@ -151,38 +146,16 @@
                return (0);
        if (intio_attached)
                return (0);
-       if (x68k_realconfig == 0)
-               cfdata_intiobus = cf; /* XXX */
 
        return (1);
 }
 
-
-/* used in console initialization: configure only MFP */
-static struct intio_attach_args initial_ia = {
-       &intio_bus,
-       0/*XXX*/,
-
-       "mfp",                  /* ia_name */
-       MFP_ADDR,               /* ia_addr */
-       0x30,                   /* ia_size */
-       MFP_INTR,               /* ia_intr */
-       -1                      /* ia_dma */
-       -1,                     /* ia_dmaintr */
-};
-
 static void
 intio_attach(device_t parent, device_t self, void *aux)
 {
        struct intio_softc *sc = device_private(self);
        struct intio_attach_args ia;
 
-       if (self == NULL) {
-               /* console only init */
-               x68k_config_found(cfdata_intiobus, NULL, &initial_ia, NULL);
-               return;
-       }
-
        intio_attached = 1;
 
        aprint_normal(" mapped at %8p\n", intiobase);
Index: sys/arch/x68k/dev/ite.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/ite.c,v
retrieving revision 1.55
diff -u -r1.55 ite.c
--- sys/arch/x68k/dev/ite.c     13 Jun 2008 13:57:58 -0000      1.55
+++ sys/arch/x68k/dev/ite.c     31 Dec 2008 13:39:49 -0000
@@ -106,6 +106,7 @@
 #include <machine/cpu.h>
 #include <machine/kbio.h>
 #include <machine/bus.h>
+#include <machine/autoconf.h>
 #include <machine/grfioctl.h>
 #include <machine/iteioctl.h>
 
@@ -229,37 +230,29 @@
        struct grf_softc *gp;
 
        gp = (struct grf_softc *)auxp;
-       if (dp) {
-               ip = (struct ite_softc *)dp;
-               if(con_itesoftc.grf != NULL
-                       /*&& con_itesoftc.grf->g_unit == gp->g_unit*/) {
-                       /*
-                        * console reinit copy params over.
-                        * and console always gets keyboard
-                        */
-                       memcpy(&ip->grf, &con_itesoftc.grf,
-                           (char *)&ip[1] - (char *)&ip->grf);
-                       con_itesoftc.grf = NULL;
-                       kbd_ite = ip;
-               }
-               ip->grf = gp;
-               iteinit(device_unit(&ip->device)); /* XXX */
-               printf(": rows %d cols %d", ip->rows, ip->cols);
-               if (kbd_ite == NULL)
-                       kbd_ite = ip;
-               printf("\n");
-       } else {
-               if (con_itesoftc.grf != NULL)
-                       return;
-               con_itesoftc.grf = gp;
-               con_itesoftc.tabs = cons_tabs;
-       }
+       ip = (struct ite_softc *)dp;
+       if(con_itesoftc.grf != NULL
+               /*&& con_itesoftc.grf->g_unit == gp->g_unit*/) {
+               /*
+                * console reinit copy params over.
+                * and console always gets keyboard
+                */
+               memcpy(&ip->grf, &con_itesoftc.grf,
+                   (char *)&ip[1] - (char *)&ip->grf);
+               con_itesoftc.grf = NULL;
+               kbd_ite = ip;
+       }
+       ip->grf = gp;
+       iteinit(device_unit(&ip->device)); /* XXX */
+       printf(": rows %d cols %d", ip->rows, ip->cols);
+       if (kbd_ite == NULL)
+               kbd_ite = ip;
+       printf("\n");
 }
 
 struct ite_softc *
 getitesp(dev_t dev)
 {
-       extern int x68k_realconfig;
 
        if (x68k_realconfig && con_itesoftc.grf == NULL)
                return device_lookup_private(&ite_cd, UNIT(dev));
@@ -294,6 +287,17 @@
        ip->flags |= ITE_INITED;
 }
 
+void
+ite_config_console(void)
+{
+       struct grf_softc *gp = &congrf;
+
+       if (con_itesoftc.grf != NULL)
+               return;
+       con_itesoftc.grf = gp;
+       con_itesoftc.tabs = cons_tabs;
+}
+
 /*
  * Perform functions necessary to setup device as a terminal emulator.
  */
Index: sys/arch/x68k/dev/mfp.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/mfp.c,v
retrieving revision 1.21
diff -u -r1.21 mfp.c
--- sys/arch/x68k/dev/mfp.c     31 Dec 2008 08:00:31 -0000      1.21
+++ sys/arch/x68k/dev/mfp.c     31 Dec 2008 13:39:49 -0000
@@ -51,6 +51,7 @@
 
 #include <machine/bus.h>
 #include <machine/cpu.h>
+#include <machine/autoconf.h>
 
 #include <arch/x68k/dev/intiovar.h>
 #include <arch/x68k/dev/mfp.h>
@@ -97,33 +98,22 @@
 {
        struct mfp_softc *sc = (struct mfp_softc *)self;
        struct intio_attach_args *ia = aux;
+       int r;
 
-       mfp_init();
+       printf("\n");
+       mfp_attached = 1;
 
-       if (sc != NULL) {
-               /* realconfig */
-               int r;
-
-               printf("\n");
-
-               mfp_attached = 1;
-               sc->sc_bst = ia->ia_bst;
-               sc->sc_intr = ia->ia_intr;
-               ia->ia_size = 0x30;
-               r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
+       mfp_init();
+       sc->sc_bst = ia->ia_bst;
+       sc->sc_intr = ia->ia_intr;
+       ia->ia_size = 0x30;
+       r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
 #ifdef DIAGNOSTIC
-               if (r)
-                       panic("IO map for MFP corruption??");
+       if (r)
+               panic("IO map for MFP corruption??");
 #endif
-               bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
-               config_search_ia(mfp_search, self, "mfp", NULL);
-       } else {
-               /*
-                * Called from config_console;
-                * calibrate the DELAY loop counter
-                */
-               mfp_calibrate_delay();
-       }
+       bus_space_map(ia->ia_bst, ia->ia_addr, 0x2000, 0, &sc->sc_bht);
+       config_search_ia(mfp_search, self, "mfp", NULL);
 }
 
 static int
@@ -134,6 +124,13 @@
        return 0;
 }
 
+void
+mfp_config_console(void)
+{
+       mfp_init();
+       mfp_calibrate_delay();
+}
+
 static void
 mfp_init(void)
 {
Index: sys/arch/x68k/include/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/include/cpu.h,v
retrieving revision 1.47
diff -u -r1.47 cpu.h
--- sys/arch/x68k/include/cpu.h 18 Dec 2008 05:56:42 -0000      1.47
+++ sys/arch/x68k/include/cpu.h 31 Dec 2008 13:39:49 -0000
@@ -188,9 +188,6 @@
 extern char *intiobase;
 extern char *intiolimit;
 
-/* autoconf.c functions */
-void   config_console(void);
-
 /* fpu.c functions */
 int    fpu_probe(void);
 
Index: sys/arch/x68k/x68k/autoconf.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/x68k/autoconf.c,v
retrieving revision 1.59
diff -u -r1.59 autoconf.c
--- sys/arch/x68k/x68k/autoconf.c       21 Dec 2008 09:35:49 -0000      1.59
+++ sys/arch/x68k/x68k/autoconf.c       31 Dec 2008 13:39:49 -0000
@@ -45,14 +45,13 @@
 #include <sys/disklabel.h>
 #include <machine/cpu.h>
 #include <machine/bootinfo.h>
+#include <machine/autoconf.h>
 
 #include <dev/scsipi/scsi_all.h>
 #include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsiconf.h>
 
 static void findroot(void);
-int x68k_config_found(struct cfdata *, struct device *, void *, cfprint_t);
-
 static struct device *scsi_find(dev_t);
 
 int x68k_realconfig;
@@ -83,62 +82,12 @@
        setroot(booted_device, booted_partition);
 }
 
-/*
- * use config_search_ia to find appropriate device, then call that device
- * directly with NULL device variable storage.  A device can then
- * always tell the difference between the real and console init
- * by checking for NULL.
- */
-int
-x68k_config_found(struct cfdata *pcfp, struct device *pdp, void *auxp,
-    cfprint_t pfn)
-{
-       struct device temp;
-       struct cfdata *cf;
-       const struct cfattach *ca;
-
-       if (x68k_realconfig)
-               return(config_found(pdp, auxp, pfn) != NULL);
-
-       if (pdp == NULL)
-               pdp = &temp;
-
-       /* XXX Emulate 'struct device' of mainbus for cfparent_match() */
-       pdp->dv_cfdata = pcfp;
-       pdp->dv_cfdriver = config_cfdriver_lookup(pcfp->cf_name);
-       pdp->dv_unit = 0;
-       if ((cf = config_search_ia(NULL, pdp, NULL, auxp)) != NULL) {
-               ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
-               if (ca != NULL) {
-                       (*ca->ca_attach)(pdp, NULL, auxp);
-                       pdp->dv_cfdata = NULL;
-                       return(1);
-               }
-       }
-       pdp->dv_cfdata = NULL;
-       return(0);
-}
-
-/*
- * this function needs to get enough configured to do a console
- * basically this means start attaching the grfxx's that support
- * the console. Kinda hacky but it works.
- */
 void
 config_console(void)
 {      
-       struct cfdata *cf;
-
-       config_init();
-
-       /*
-        * we need mainbus' cfdata.
-        */
-       cf = config_rootsearch(NULL, "mainbus", NULL);
-       if (cf == NULL)
-               panic("no mainbus");
-       x68k_config_found(cf, NULL, __UNCONST("intio"), NULL);
-       x68k_config_found(cf, NULL, __UNCONST("grfbus"), NULL);
+       mfp_config_console();
+       grf_config_console();
+       ite_config_console();
 }
 
 dev_t  bootdev = 0;
Index: sys/arch/x68k/x68k/iodevice.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/x68k/iodevice.h,v
retrieving revision 1.16
diff -u -r1.16 iodevice.h
--- sys/arch/x68k/x68k/iodevice.h       18 Dec 2008 05:56:42 -0000      1.16
+++ sys/arch/x68k/x68k/iodevice.h       31 Dec 2008 13:39:50 -0000
@@ -357,13 +357,3 @@
 #if defined(_KERNEL) && !defined(LOCORE)
 extern volatile struct IODEVICE *IODEVbase;
 #endif
-
-#if 0
-/*
- * devices that need to configure before console use this
- * *and know it* (i.e. everything is really tight certain params won't be
- * passed in some cases and the devices will deal with it)
- */
-#include <sys/device.h>
-int x68k_config_found(struct cfdata *, struct device *, void *, cfprint_t);
-#endif
Index: sys/arch/x68k/x68k/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/x68k/machdep.c,v
retrieving revision 1.154
diff -u -r1.154 machdep.c
--- sys/arch/x68k/x68k/machdep.c        30 Nov 2008 18:21:36 -0000      1.154
+++ sys/arch/x68k/x68k/machdep.c        31 Dec 2008 13:39:50 -0000
@@ -139,6 +139,7 @@
 #include <sys/device.h>
 
 #include <machine/bus.h>
+#include <machine/autoconf.h>
 #include <arch/x68k/dev/intiovar.h>
 
 void initcpu(void);
--- /dev/null   2008-12-31 22:39:23.000000000 +0900
+++ sys/arch/x68k/include/autoconf.h    2008-12-31 22:32:13.000000000 +0900
@@ -0,0 +1,43 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 2008 Tetsuya Isaki. 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. 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 _X68K_AUTOCONF_H_
+#define _X68K_AUTOCONF_H_
+
+extern void config_console(void);
+extern void mfp_config_console(void);
+extern void grf_config_console(void);
+extern void ite_config_console(void);
+
+extern int  x68k_realconfig;   /* XXX should be removed ? */
+
+struct grf_softc;
+extern struct grf_softc congrf;        /* XXX Hmm... */
+
+#endif /* !_X68K_AUTOCONF_H_ */


Home | Main Index | Thread Index | Old Index