Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xfree86 / os-support / bsd / bsd_axp.c
CommitLineData
a09e091a
JB
1
2#ifdef HAVE_XORG_CONFIG_H
3#include <xorg-config.h>
4#endif
5
6#include <X11/X.h>
7#include "os.h"
8#include "xf86.h"
9#include "xf86Priv.h"
10#include "shared/xf86Axp.h"
11#include <sys/param.h>
12#include "xf86_OSlib.h"
13#include <stdio.h>
14#include <sys/sysctl.h>
15
16axpDevice bsdGetAXP(void);
17
18/*
19 * BSD does a very nice job providing system information to
20 * user space programs. Unfortunately it doesn't provide all
21 * the information required. Therefore we just obtain the
22 * system type and look up the rest from a list we maintain
23 * ourselves.
24 */
25
26typedef struct {
27 char *name;
28 int type;
29} _AXP;
30
31static _AXP axpList[] = {
32 {"apecs", APECS},
33 {"pyxis", PYXIS},
34 {"cia", CIA},
35 {"irongate", IRONGATE},
36 {"lca", LCA},
37 {"t2", T2},
38 {"tsunami", TSUNAMI},
39 {NULL, SYS_NONE}
40};
41
42axpDevice
43bsdGetAXP(void)
44{
45 int i;
46 char sysname[64];
47 size_t len = sizeof(sysname);
48
49#ifdef __OpenBSD__
50 int mib[3];
51 int error;
52
53 mib[0] = CTL_MACHDEP;
54 mib[1] = CPU_CHIPSET;
55 mib[2] = CPU_CHIPSET_TYPE;
56
57 if ((error = sysctl(mib, 3, &sysname, &len, NULL, 0)) < 0)
58#else
59 if ((sysctlbyname("hw.chipset.type", &sysname, &len, 0, 0)) < 0)
60#endif
61 FatalError("bsdGetAXP: can't find machine type\n");
62#ifdef DEBUG
63 xf86Msg(X_INFO, "AXP is a: %s\n", sysname);
64#endif
65 for (i = 0;; i++) {
66 if (axpList[i].name == NULL)
67 return SYS_NONE;
68 if (!strcmp(sysname, axpList[i].name))
69 return axpList[i].type;
70 }
71}