Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Renamed platid_search() to platid_search_data() and...



details:   https://anonhg.NetBSD.org/src/rev/516f8b77fd23
branches:  trunk
changeset: 515425:516f8b77fd23
user:      takemura <takemura%NetBSD.org@localhost>
date:      Mon Sep 24 14:29:30 2001 +0000

description:
Renamed platid_search() to platid_search_data() and added new platid_search().
Platid_name() was re-implemented using platid_search().

diffstat:

 sys/arch/arm/sa11x0/sa1111.c         |    4 +-
 sys/arch/arm/sa11x0/sa11x1_pcic.c    |    4 +-
 sys/arch/hpc/hpc/Makefile            |    9 +-
 sys/arch/hpc/hpc/platid.c            |   45 ++++++++-----
 sys/arch/hpc/hpc/platid.h            |    5 +-
 sys/arch/hpc/hpc/platid_test.c       |  118 +++++++++++++++++++++++++++++-----
 sys/arch/hpc/hpc/platid_test.canon   |   24 +++++++
 sys/arch/hpcarm/sa11x0/sa1111.c      |    4 +-
 sys/arch/hpcarm/sa11x0/sa11x1_pcic.c |    4 +-
 sys/arch/hpcmips/vr/vrc4172pwm.c     |    4 +-
 sys/arch/hpcmips/vr/vrpiu.c          |    4 +-
 11 files changed, 169 insertions(+), 56 deletions(-)

diffs (truncated from 419 to 300 lines):

diff -r eb67def15dda -r 516f8b77fd23 sys/arch/arm/sa11x0/sa1111.c
--- a/sys/arch/arm/sa11x0/sa1111.c      Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/arm/sa11x0/sa1111.c      Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sa1111.c,v 1.2 2001/08/01 14:02:58 rjs Exp $  */
+/*      $NetBSD: sa1111.c,v 1.3 2001/09/24 14:29:30 takemura Exp $     */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
        sc->sc_piot = psc->sc_iot;
        sc->sc_gpioh = psc->sc_gpioh;
 #ifdef hpcarm
-       if ((p = platid_search(&platid, sacc_platid_table)) == NULL)
+       if ((p = platid_search_data(&platid, sacc_platid_table)) == NULL)
                return;
 
        gpiopin = (int) p->data;
diff -r eb67def15dda -r 516f8b77fd23 sys/arch/arm/sa11x0/sa11x1_pcic.c
--- a/sys/arch/arm/sa11x0/sa11x1_pcic.c Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/arm/sa11x0/sa11x1_pcic.c Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: sa11x1_pcic.c,v 1.2 2001/07/30 10:46:08 rjs Exp $        */
+/*      $NetBSD: sa11x1_pcic.c,v 1.3 2001/09/24 14:29:30 takemura Exp $        */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -139,7 +139,7 @@
        sc->sc_pc.sc_iot = psc->sc_iot;
        sc->sc_ioh = psc->sc_ioh;
 #ifdef hpcarm
-       p = platid_search(&platid, sacpcic_platid_table);
+       p = platid_search_data(&platid, sacpcic_platid_table);
 #endif
 
        for(i = 0; i < 2; i++) {
diff -r eb67def15dda -r 516f8b77fd23 sys/arch/hpc/hpc/Makefile
--- a/sys/arch/hpc/hpc/Makefile Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/hpc/hpc/Makefile Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 2001/05/01 13:26:20 enami Exp $
+#      $NetBSD: Makefile,v 1.4 2001/09/24 14:29:30 takemura Exp $
 
 HOST_CC ?= /usr/bin/cc
 
@@ -7,14 +7,13 @@
        diff  platid_test.out  platid_test.canon
 
 platid_test: platid.c platid_mask.c platid_test.c platid_name.c
-       ln -sf ./ ./machine
-       ln -sf ../../mips/include ./mips
-       $(HOST_CC) -I. -DPLATID_TEST \
+       ln -sf ../../hpcmips/include ./machine
+       $(HOST_CC) -Dhpcmips -Dhpcarm -Dhpcsh -I/usr/include -I. -I../.. -DPLATID_TEST \
            platid.c platid_mask.c platid_name.c platid_test.c -o $@
 
 CLEANFILES+=   platid_test platid_test.out machine mips
 
 clean:
-       rm -f machine mips platid_test.out platid_test
+       rm -f machine platid_test.out platid_test
 
 .include <bsd.subdir.mk>
diff -r eb67def15dda -r 516f8b77fd23 sys/arch/hpc/hpc/platid.c
--- a/sys/arch/hpc/hpc/platid.c Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/hpc/hpc/platid.c Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: platid.c,v 1.1 2001/01/28 02:52:21 uch Exp $   */
+/*     $NetBSD: platid.c,v 1.2 2001/09/24 14:29:31 takemura Exp $      */
 
 /*-
  * Copyright (c) 1999-2001
@@ -111,26 +111,17 @@
 tchar*
 platid_name(platid_t *platid)
 {
-       int match_level;
-       struct platid_name *p, *match, *pe;
+       struct platid_name *match;
 
-       match_level = 0;
-       pe = &platid_name_table[platid_name_table_size];
-       for (p = platid_name_table; p < pe; p++) {
-               int res = platid_match(platid, p->mask);
-               if (match_level < res) {
-                       match = p;
-                       match_level = res;
-               }
-       }
-       if (0 < match_level)
-               return (match->name);
-       else
-               return (TEXT("UNKNOWN"));
+       match = platid_search(platid,
+           platid_name_table, platid_name_table_size,
+           sizeof(struct platid_name));
+
+       return ((match != NULL) ? match->name : TEXT("UNKNOWN"));
 }
 
 struct platid_data *
-platid_search(platid_t *platid, struct platid_data *datap)
+platid_search_data(platid_t *platid, struct platid_data *datap)
 {
 
        while (datap->mask != NULL && !platid_match(platid, datap->mask))
@@ -139,3 +130,23 @@
                return NULL;
        return datap;
 }
+
+void *
+platid_search(platid_t *platid, void *base, int nmemb, int size)
+{
+       int i, match_level, res;
+       void *match;
+
+       match_level = 0;
+       match = NULL;
+       for (i = 0; i < nmemb; i++) {
+               res = platid_match(platid, *(platid_mask_t**)base);
+               if (match_level < res) {
+                       match_level = res;
+                       match = base;
+               }
+               (char *)base += size;
+       }
+
+       return (match);
+}
diff -r eb67def15dda -r 516f8b77fd23 sys/arch/hpc/hpc/platid.h
--- a/sys/arch/hpc/hpc/platid.h Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/hpc/hpc/platid.h Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: platid.h,v 1.5 2001/05/30 12:28:42 mrg Exp $   */
+/*     $NetBSD: platid.h,v 1.6 2001/09/24 14:29:31 takemura Exp $      */
 
 /*-
  * Copyright (c) 1999-2001
@@ -143,7 +143,8 @@
 int platid_match(platid_t *, platid_mask_t *);
 int platid_match_sub(platid_t *, platid_mask_t *, int);
 tchar* platid_name(platid_t *);
-struct platid_data *platid_search(platid_t *, struct platid_data *);
+struct platid_data *platid_search_data(platid_t *, struct platid_data *);
+void *platid_search(platid_t *, void *, int, int);
 __END_DECLS
 
 #if defined(_KERNEL_OPT)
diff -r eb67def15dda -r 516f8b77fd23 sys/arch/hpc/hpc/platid_test.c
--- a/sys/arch/hpc/hpc/platid_test.c    Mon Sep 24 14:19:10 2001 +0000
+++ b/sys/arch/hpc/hpc/platid_test.c    Mon Sep 24 14:29:30 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: platid_test.c,v 1.1 2001/01/28 02:52:22 uch Exp $      */
+/*     $NetBSD: platid_test.c,v 1.2 2001/09/24 14:29:31 takemura Exp $ */
 
 /*-
  * Copyright (c) 1999
@@ -122,7 +122,7 @@
 }
 
 void
-platid_search_test()
+platid_search_data_test()
 {
        char *mcr700str = "MC-R700";
        char *mcr500str = "MC-R500";
@@ -143,25 +143,101 @@
                { NULL, defstr }
        };
 
+       printf("#\n");
+       printf("# platid_search_data() test\n");
+       printf("#\n");
+
        printf("search MC-R700 in no default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_700A, d_null)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_700A, d_null)->data);
        printf("search MC-R500 in no default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_500, d_null)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_500, d_null)->data);
        printf("search MC/R530 in no default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_530, d_null)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_530, d_null)->data);
        printf("search non exist MC-R300 in no default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_300, d_null) == NULL?"NULL":"any!!bug!");
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_300, d_null) == NULL?"NULL":"any!!bug!");
        printf("search MC-R700 in default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_700A, d_default)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_700A, d_default)->data);
        printf("search MC-R500 in default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_500, d_default)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_500, d_default)->data);
        printf("search MC/R530 in default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_530, d_default)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_530, d_default)->data);
        printf("search non exist MC-R300 in default table: %s\n",
-               (char *)platid_search(&platid_mask_MACH_NEC_MCR_300, d_default)->data);
+               (char *)platid_search_data(&platid_mask_MACH_NEC_MCR_300, d_default)->data);
 }
 
 void
+platid_search_test()
+{
+       struct platid_name *res;
+       struct platid_name tab[] = {
+               { &platid_mask_MACH_NEC_MCR,
+                 TEXT("MC-R") },
+               { &platid_mask_MACH_NEC_MCR_3XX,
+                 TEXT("MC-R300 series") },
+               { &platid_mask_MACH_NEC_MCR_300,
+                 TEXT("MC-R300") },
+               { &platid_mask_MACH_NEC_MCR_330,
+                 TEXT("MC-R330") },
+       };
+       int i, nmemb = sizeof(tab)/sizeof(*tab);
+
+       printf("#\n");
+       printf("# platid_search() test\n");
+       printf("#\n");
+       printf("# table contains: ");
+       for (i = 0; i < nmemb; i++)
+               printf(" %s%s", tab[i].name, i < nmemb - 1 ? "," : "");
+       printf("\n");
+
+       res = platid_search(&platid_mask_MACH_NEC_MCR_300,
+           tab, nmemb, sizeof(struct platid_name));
+       printf("search MC-R300: %s\n",
+           (res == NULL) ? "not found" : res->name);
+
+       res = platid_search(&platid_mask_MACH_NEC_MCR,
+           tab, nmemb, sizeof(struct platid_name));
+       printf("search MC-R: %s\n",
+           (res == NULL) ? "not found" : res->name);
+
+       res = platid_search(&platid_mask_MACH_NEC_MCR_700,
+           tab, nmemb, sizeof(struct platid_name));
+       printf("search MC-R700: %s\n",
+           (res == NULL) ? "not found" : res->name);
+
+       res = platid_search(&platid_mask_MACH_NEC_MCR_320,
+           tab, nmemb, sizeof(struct platid_name));
+       printf("search MC-R320: %s\n",
+           (res == NULL) ? "not found" : res->name);
+
+       res = platid_search(&platid_mask_MACH_NEC_MCCS_12,
+           tab, nmemb, sizeof(struct platid_name));
+       printf("search MC-CS12: %s\n",
+           (res == NULL) ? "not found" : res->name);
+}
+
+
+void
+platid_name_test()
+{
+       int i, err;
+
+       printf("#\n");
+       printf("# platid_name() test\n");
+       printf("#\n");
+       err = 0;
+       for (i = 0; i < platid_name_table_size; i++) {
+               if (strcmp(platid_name(platid_name_table[i].mask), 
+                   platid_name_table[i].name) != 0) {
+                       printf("%s mismatch\n", platid_name_table[i].name);
+                       err++;
+               }
+       }
+       printf("%s\n", err ? "ERROR" : "ok");
+}
+
+#define __PP(p)        PLATID_DEREFP(p)
+
+void
 main()
 {
        platid_t pid = platid_unknown;
@@ -172,26 +248,28 @@
        pid.dw.dw1 =    PLATID_MACH_NEC_MCR_500;
 
        printf("CPU_MIPS:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS)) ? "O" : "X");
        printf("CPU_MIPS_VR:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS_VR) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS_VR)) ? "O" : "X");
        printf("CPU_MIPS_VR41XX:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS_VR_41XX) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS_VR_41XX)) ? "O" : "X");
        printf("CPU_MIPS_VR4102:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS_VR_4102) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS_VR_4102)) ? "O" : "X");
        printf("CPU_MIPS_VR4111:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS_VR_4111) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS_VR_4111)) ? "O" : "X");
        printf("CPU_MIPS_VR4121:\t%s\n",
-              platid_match(&pid, GENERIC_MIPS_VR_4121) ? "O" : "X");
+              platid_match(&pid, __PP(GENERIC_MIPS_VR_4121)) ? "O" : "X");
        printf("NEC_MCR:\t%s\n",
-              platid_match(&pid, NEC_MCR) ? "O" : "X");



Home | Main Index | Thread Index | Old Index