1/*	$NetBSD: platid.h,v 1.3 2005/12/11 12:17:25 christos Exp $	*/
2
3/*-
4 * Copyright (c) 1999-2001
5 *         Shin Takemura and PocketBSD Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by the PocketBSD project
18 *	and its contributors.
19 * 4. Neither the name of the project nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#ifndef _HPC_PLATID_H_
38#define _HPC_PLATID_H_
39
40#include <sys/cdefs.h>
41
42#define PLATID_FLAGS_BITS		8
43#define PLATID_CPU_SUBMODEL_BITS	6
44#define PLATID_CPU_MODEL_BITS		6
45#define PLATID_CPU_SERIES_BITS		6
46#define PLATID_CPU_ARCH_BITS		6
47
48#define PLATID_SUBMODEL_BITS		8
49#define PLATID_MODEL_BITS		8
50#define PLATID_SERIES_BITS		6
51#define PLATID_VENDOR_BITS		10
52
53typedef union {
54	struct {
55		unsigned long dw0, dw1;
56	} dw;
57#if BYTE_ORDER == LITTLE_ENDIAN
58	struct platid {
59		unsigned int 	flags		:PLATID_FLAGS_BITS;
60		unsigned int	cpu_submodel	:PLATID_CPU_SUBMODEL_BITS;
61		unsigned int	cpu_model	:PLATID_CPU_MODEL_BITS;
62		unsigned int	cpu_series	:PLATID_CPU_SERIES_BITS;
63		unsigned int	cpu_arch	:PLATID_CPU_ARCH_BITS;
64
65		unsigned int 	submodel	:PLATID_SUBMODEL_BITS;
66		unsigned int	model		:PLATID_MODEL_BITS;
67		unsigned int	series		:PLATID_SERIES_BITS;
68		unsigned int	vendor		:PLATID_VENDOR_BITS;
69	} s;
70#else
71#error BYTE_ORDER != LITTLE_ENDIAN
72#endif
73} platid_t;
74
75typedef platid_t platid_mask_t;
76
77#ifdef UNICODE
78typedef unsigned short tchar;
79#ifndef TEXT
80#define TEXT(x)		L##x
81#endif
82#else
83typedef char tchar;
84#define TEXT(x)		x
85#endif
86
87struct platid_name {
88	platid_mask_t *mask;
89	const tchar *name;
90};
91
92struct platid_data {
93	platid_mask_t *mask;
94	void *data;
95};
96
97#define PLATID_FLAGS_SHIFT		0
98#define PLATID_CPU_SUBMODEL_SHIFT	8
99#define PLATID_CPU_MODEL_SHIFT		14
100#define PLATID_CPU_SERIES_SHIFT		20
101#define PLATID_CPU_ARCH_SHIFT		26
102
103#define PLATID_SUBMODEL_SHIFT		0
104#define PLATID_MODEL_SHIFT		8
105#define PLATID_SERIES_SHIFT		16
106#define PLATID_VENDOR_SHIFT		22
107
108#define PLATID_FLAGS_MASK						\
109	(((1 << PLATID_FLAGS_BITS) - 1) << PLATID_FLAGS_SHIFT)
110#define PLATID_CPU_SUBMODEL_MASK					\
111	(((1 << PLATID_CPU_SUBMODEL_BITS) - 1) << PLATID_CPU_SUBMODEL_SHIFT)
112#define PLATID_CPU_MODEL_MASK						\
113	(((1 << PLATID_CPU_MODEL_BITS) - 1) << PLATID_CPU_MODEL_SHIFT)
114#define PLATID_CPU_SERIES_MASK						\
115	(((1 << PLATID_CPU_SERIES_BITS) - 1) << PLATID_CPU_SERIES_SHIFT)
116#define PLATID_CPU_ARCH_MASK						\
117	(((1 << PLATID_CPU_ARCH_BITS) - 1) << PLATID_CPU_ARCH_SHIFT)
118
119#define PLATID_SUBMODEL_MASK						\
120	(((1 << PLATID_SUBMODEL_BITS) - 1) << PLATID_SUBMODEL_SHIFT)
121#define PLATID_MODEL_MASK						\
122	(((1 << PLATID_MODEL_BITS) - 1) << PLATID_MODEL_SHIFT)
123#define PLATID_SERIES_MASK						\
124	(((1 << PLATID_SERIES_BITS) - 1) << PLATID_SERIES_SHIFT)
125#define PLATID_VENDOR_MASK						\
126	(((1 << PLATID_VENDOR_BITS) - 1) << PLATID_VENDOR_SHIFT)
127
128#define	PLATID_UNKNOWN		0
129#define	PLATID_WILD		PLATID_UNKNOWN
130#define PLATID_DEREFP(pp)	((platid_t *)(pp))
131#define PLATID_DEREF(pp)	(*PLATID_DEREFP(pp))
132
133__BEGIN_DECLS
134extern platid_t platid_unknown;
135extern platid_t platid_wild;
136extern platid_t platid;
137extern struct platid_name platid_name_table[];
138extern int platid_name_table_size;
139
140void platid_ntoh(platid_t *);
141void platid_hton(platid_t *);
142int platid_match(platid_t *, platid_mask_t *);
143int platid_match_sub(platid_t *, platid_mask_t *, int);
144const tchar *platid_name(platid_t *);
145struct platid_data *platid_search_data(platid_t *, struct platid_data *);
146void *platid_search(platid_t *, void *, int, int);
147
148#ifdef PLATID_TEST
149void platid_dump(const char *, void *);
150#endif
151__END_DECLS
152
153#if defined(_KERNEL_OPT)
154#include "opt_spec_platform.h"
155#endif
156#include <machine/platid_generated.h>
157
158#endif /* _HPC_PLATID_H_ */
159