xref: /netbsd/sys/arch/arc/arc/platform.c (revision 6550d01e)
1 /*	$NetBSD: platform.c,v 1.6 2008/04/28 20:23:13 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by SODA Noriyuki.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.6 2008/04/28 20:23:13 martin Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kcore.h>
38 
39 #include <machine/platform.h>
40 #include <arc/arc/arcbios.h>
41 
42 struct platform *platform = NULL;
43 
44 static void print_platform(struct platform *);
45 
46 static void
47 print_platform(struct platform *p)
48 {
49 	printf("\"%s %s%s\" (%s, %s)",
50 	    p->vendor, p->model, p->variant,
51 	    p->vendor_id ? p->vendor_id : "NULL",
52 	    p->system_id);
53 }
54 
55 int
56 ident_platform(void)
57 {
58 	int i, rv, matched = -1, match = 0, ambiguous_match = 0;
59 
60 	for (i = 0; i < nplattab; i++) {
61 		rv = (*plattab[i]->match)(plattab[i]);
62 		if (rv > match) {
63 			match = rv;
64 			matched = i;
65 			ambiguous_match = 0;
66 		} else if (rv == match) {
67 			++ambiguous_match;
68 		}
69 	}
70 	if (ambiguous_match) {
71 		/* assumes that ARC Firmware printf() can be used. */
72 		printf("ambiguous platform detection between ");
73 		print_platform(plattab[matched]);
74 		for (i = 0; i < nplattab; i++) {
75 			if (i == matched)
76 				continue;
77 			rv = (*plattab[i]->match)(plattab[i]);
78 			if (rv < match)
79 				continue;
80 			if (--ambiguous_match)
81 				printf(", ");
82 			else
83 				printf(" and ");
84 			print_platform(plattab[i]);
85 		}
86 		printf(". ");
87 		print_platform(plattab[matched]);
88 		printf(" is choosed.\n");
89 	}
90 	if (match)
91 		platform = plattab[matched];
92 	return match;
93 }
94 
95 int
96 platform_generic_match(struct platform *p)
97 {
98 
99 	if (strcmp(arc_id, p->system_id) == 0 &&
100 	    (p->vendor_id == NULL || strcmp(arc_vendor_id, p->vendor_id) == 0))
101 		return 1;
102 
103 	return 0;
104 }
105 
106 void
107 platform_nop(void)
108 {
109 }
110