Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic use locator passing versions of xxxsubmatch() and...



details:   https://anonhg.NetBSD.org/src/rev/61a9b3985323
branches:  trunk
changeset: 569909:61a9b3985323
user:      drochner <drochner%NetBSD.org@localhost>
date:      Mon Sep 13 12:34:00 2004 +0000

description:
use locator passing versions of xxxsubmatch() and simplify the code by
using arithmetics instead of case statements

diffstat:

 sys/dev/ic/i82365.c    |  111 ++++++++++--------------------------------------
 sys/dev/ic/i82365var.h |    5 +-
 sys/dev/ic/tcic2.c     |   69 ++++++++++-------------------
 3 files changed, 51 insertions(+), 134 deletions(-)

diffs (truncated from 339 to 300 lines):

diff -r 4c47fc014fe4 -r 61a9b3985323 sys/dev/ic/i82365.c
--- a/sys/dev/ic/i82365.c       Mon Sep 13 12:22:52 2004 +0000
+++ b/sys/dev/ic/i82365.c       Mon Sep 13 12:34:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i82365.c,v 1.86 2004/08/16 15:46:37 mycroft Exp $      */
+/*     $NetBSD: i82365.c,v 1.87 2004/09/13 12:34:00 drochner Exp $     */
 
 /*
  * Copyright (c) 2004 Charles M. Hannum.  All rights reserved.
@@ -49,7 +49,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.86 2004/08/16 15:46:37 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i82365.c,v 1.87 2004/09/13 12:34:00 drochner Exp $");
 
 #define        PCICDEBUG
 
@@ -70,6 +70,8 @@
 #include <dev/ic/i82365reg.h>
 #include <dev/ic/i82365var.h>
 
+#include "locators.h"
+
 #ifdef PCICDEBUG
 int    pcic_debug = 0;
 #define        DPRINTF(arg) if (pcic_debug) printf arg;
@@ -87,7 +89,8 @@
 void   pcic_attach_socket __P((struct pcic_handle *));
 void   pcic_attach_socket_finish __P((struct pcic_handle *));
 
-int    pcic_submatch __P((struct device *, struct cfdata *, void *));
+int    pcic_submatch __P((struct device *, struct cfdata *,
+                          const locdesc_t *, void *));
 int    pcic_print  __P((void *arg, const char *pnp));
 int    pcic_intr_socket __P((struct pcic_handle *));
 void   pcic_poll_intr __P((void *));
@@ -247,6 +250,7 @@
 
                h->ph_parent = (struct device *)sc;
                h->chip = chip;
+               h->socket = socket;
                h->sock = chip * PCIC_CHIP_OFFSET + socket * PCIC_SOCKET_OFFSET;
                h->laststate = PCIC_LASTSTATE_EMPTY;
                /* initialize pcic_read and pcic_write functions */
@@ -392,6 +396,8 @@
 {
        struct pcmciabus_attach_args paa;
        struct pcic_softc *sc = (struct pcic_softc *)h->ph_parent;
+       int help[3];
+       locdesc_t *ldesc = (void *)help; /* XXX */
 
        /* initialize the rest of the handle */
 
@@ -408,7 +414,12 @@
        paa.iobase = sc->iobase;
        paa.iosize = sc->iosize;
 
-       h->pcmcia = config_found_sm(&sc->dev, &paa, pcic_print, pcic_submatch);
+       ldesc->len = 2;
+       ldesc->locs[PCMCIABUSCF_CONTROLLER] = h->chip;
+       ldesc->locs[PCMCIABUSCF_SOCKET] = h->socket;
+
+       h->pcmcia = config_found_sm_loc(&sc->dev, "pcmciabus", ldesc, &paa,
+                                       pcic_print, pcic_submatch);
        if (h->pcmcia == NULL) {
                h->flags &= ~PCIC_FLAG_SOCKETP;
                return;
@@ -511,24 +522,9 @@
        void *arg;
 {
        struct pcic_handle *h = arg;
-       const char *cs;
+       char cs[4];
 
-       switch (h->sock) {
-       case C0SA:
-               cs = "0,0";
-               break;
-       case C0SB:
-               cs = "0,1";
-               break;
-       case C1SA:
-               cs = "1,0";
-               break;
-       case C1SB:
-               cs = "1,1";
-               break;
-       default:
-               panic("pcic_create_event_thread: unknown pcic socket");
-       }
+       snprintf(cs, sizeof(cs), "%d,%d", h->chip, h->socket);
 
        if (kthread_create1(pcic_event_thread, h, &h->event_thread,
            "%s,%s", h->ph_parent->dv_xname, cs)) {
@@ -646,64 +642,20 @@
 }
 
 int
-pcic_submatch(parent, cf, aux)
+pcic_submatch(parent, cf, ldesc, aux)
        struct device *parent;
        struct cfdata *cf;
+       const locdesc_t *ldesc;
        void *aux;
 {
 
-       struct pcmciabus_attach_args *paa = aux;
-       struct pcic_handle *h = (struct pcic_handle *) paa->pch;
-
-       switch (h->sock) {
-       case C0SA:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&
-                   cf->pcmciabuscf_controller != 0)
-                       return 0;
-               if (cf->pcmciabuscf_socket !=
-                   PCMCIABUSCF_SOCKET_DEFAULT &&
-                   cf->pcmciabuscf_socket != 0)
-                       return 0;
-
-               break;
-       case C0SB:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&
-                   cf->pcmciabuscf_controller != 0)
-                       return 0;
-               if (cf->pcmciabuscf_socket !=
-                   PCMCIABUSCF_SOCKET_DEFAULT &&
-                   cf->pcmciabuscf_socket != 1)
+       if (cf->cf_loc[PCMCIABUSCF_CONTROLLER] != PCMCIABUSCF_CONTROLLER_DEFAULT &&
+           cf->cf_loc[PCMCIABUSCF_CONTROLLER] != ldesc->locs[PCMCIABUSCF_CONTROLLER])
                        return 0;
-
-               break;
-       case C1SA:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&
-                   cf->pcmciabuscf_controller != 1)
-                       return 0;
-               if (cf->pcmciabuscf_socket !=
-                   PCMCIABUSCF_SOCKET_DEFAULT &&
-                   cf->pcmciabuscf_socket != 0)
+       if (cf->cf_loc[PCMCIABUSCF_SOCKET] != PCMCIABUSCF_SOCKET_DEFAULT &&
+           cf->cf_loc[PCMCIABUSCF_SOCKET] != ldesc->locs[PCMCIABUSCF_SOCKET])
                        return 0;
 
-               break;
-       case C1SB:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&
-                   cf->pcmciabuscf_controller != 1)
-                       return 0;
-               if (cf->pcmciabuscf_socket !=
-                   PCMCIABUSCF_SOCKET_DEFAULT &&
-                   cf->pcmciabuscf_socket != 1)
-                       return 0;
-
-               break;
-       default:
-               panic("unknown pcic socket");
-       }
-
        return (config_match(parent, cf, aux));
 }
 
@@ -719,22 +671,7 @@
        if (pnp)
                aprint_normal("pcmcia at %s", pnp);
 
-       switch (h->sock) {
-       case C0SA:
-               aprint_normal(" controller 0 socket 0");
-               break;
-       case C0SB:
-               aprint_normal(" controller 0 socket 1");
-               break;
-       case C1SA:
-               aprint_normal(" controller 1 socket 0");
-               break;
-       case C1SB:
-               aprint_normal(" controller 1 socket 1");
-               break;
-       default:
-               panic("unknown pcic socket");
-       }
+       aprint_normal(" controller %d socket %d", h->chip, h->socket);
 
        return (UNCONF);
 }
diff -r 4c47fc014fe4 -r 61a9b3985323 sys/dev/ic/i82365var.h
--- a/sys/dev/ic/i82365var.h    Mon Sep 13 12:22:52 2004 +0000
+++ b/sys/dev/ic/i82365var.h    Mon Sep 13 12:34:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i82365var.h,v 1.20 2004/08/12 13:37:40 mycroft Exp $   */
+/*     $NetBSD: i82365var.h,v 1.21 2004/09/13 12:34:00 drochner Exp $  */
 
 /*
  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
@@ -58,7 +58,8 @@
 
        int     vendor;         /* vendor of chip */
        int     chip;           /* chip index 0 or 1 */
-       int     sock;
+       int     socket;         /* socket index 0 or 1 */
+       int     sock;           /* register offset */
        int     flags;
        int     laststate;
        int     memalloc;
diff -r 4c47fc014fe4 -r 61a9b3985323 sys/dev/ic/tcic2.c
--- a/sys/dev/ic/tcic2.c        Mon Sep 13 12:22:52 2004 +0000
+++ b/sys/dev/ic/tcic2.c        Mon Sep 13 12:34:00 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcic2.c,v 1.16 2004/08/11 06:56:57 mycroft Exp $       */
+/*     $NetBSD: tcic2.c,v 1.17 2004/09/13 12:34:00 drochner Exp $      */
 
 /*
  * Copyright (c) 1998, 1999 Christoph Badura.  All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcic2.c,v 1.16 2004/08/11 06:56:57 mycroft Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcic2.c,v 1.17 2004/09/13 12:34:00 drochner Exp $");
 
 #undef TCICDEBUG
 
@@ -51,6 +51,8 @@
 #include <dev/ic/tcic2reg.h>
 #include <dev/ic/tcic2var.h>
 
+#include "locators.h"
+
 #ifdef TCICDEBUG
 int    tcic_debug = 1;
 #define        DPRINTF(arg) if (tcic_debug) printf arg;
@@ -68,7 +70,8 @@
 void   tcic_attach_socket __P((struct tcic_handle *));
 void   tcic_init_socket __P((struct tcic_handle *));
 
-int    tcic_submatch __P((struct device *, struct cfdata *, void *));
+int    tcic_submatch __P((struct device *, struct cfdata *,
+                          const locdesc_t *, void *));
 int    tcic_print  __P((void *arg, const char *pnp));
 int    tcic_intr_socket __P((struct tcic_handle *));
 
@@ -409,6 +412,8 @@
        struct tcic_handle *h;
 {
        struct pcmciabus_attach_args paa;
+       int help[3];
+       locdesc_t *ldesc = (void *)help; /* XXX */
 
        /* initialize the rest of the handle */
 
@@ -425,8 +430,12 @@
        paa.iobase = h->sc->iobase;
        paa.iosize = h->sc->iosize;
 
-       h->pcmcia = config_found_sm(&h->sc->dev, &paa, tcic_print,
-           tcic_submatch);
+       ldesc->len = 2;
+       ldesc->locs[PCMCIABUSCF_CONTROLLER] = 0;
+       ldesc->locs[PCMCIABUSCF_SOCKET] = h->sock;
+
+       h->pcmcia = config_found_sm_loc(&h->sc->dev, "pcmciabus", ldesc, &paa,
+                                       tcic_print, tcic_submatch);
 
        /* if there's actually a pcmcia device attached, initialize the slot */
 
@@ -529,41 +538,19 @@
 }
 
 int
-tcic_submatch(parent, cf, aux)
+tcic_submatch(parent, cf, ldesc, aux)
        struct device *parent;
        struct cfdata *cf;
+       const locdesc_t *ldesc;
        void *aux;
 {
 
-       struct pcmciabus_attach_args *paa = aux;
-       struct tcic_handle *h = (struct tcic_handle *) paa->pch;
-
-       switch (h->sock) {
-       case 0:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&
-                   cf->pcmciabuscf_controller != 0)
-                       return 0;
-               if (cf->pcmciabuscf_socket !=
-                   PCMCIABUSCF_SOCKET_DEFAULT &&
-                   cf->pcmciabuscf_socket != 0)
-                       return 0;
-
-               break;
-       case 1:
-               if (cf->pcmciabuscf_controller !=
-                   PCMCIABUSCF_CONTROLLER_DEFAULT &&



Home | Main Index | Thread Index | Old Index