summaryrefslogtreecommitdiff
path: root/sysutils/i810switch/patches/patch-ac
blob: c1aa74b7b5a6014fc75e96b99d8e356b13d67174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
$NetBSD: patch-ac,v 1.2 2011/10/01 22:32:11 dholland Exp $

--- i810switch.c.orig	2005-06-12 04:36:36.000000000 +0000
+++ i810switch.c
@@ -1,3 +1,4 @@
+#include <assert.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -9,7 +10,11 @@
 #include <errno.h>
 
 #define VERSION "0.6.5beta"
+#ifdef __NetBSD__
+#define CMD_LSPCI "pcictl /dev/pci0"
+#else
 #define CMD_LSPCI "lspci"
+#endif
 
 static const char *Opt_lcd = NULL;
 static const char *Opt_crt = NULL;
@@ -49,19 +54,31 @@ struct i810_par {
 
 
 /* PCI IDs */
-#define I810STR			"8086:7121"
-#define I810ESTR		"8086:7123"
-#define I810_DC100STR_1		"8086:7125"
-#define I810_DC100STR_2		"8086:1102"
-#define I810_IGSTR		"8086:1112"
-#define I810_CFCSTR		"8086:1132"
-#define I830STR			"8086:3577"
-#define I845STR			"8086:2562"
-#define I855STR			"8086:3582"
-//#define I865STR			"8086:2572"
-#define I915STR			"8086:2592"
-#define MEMSTR			"Memory at"
+static const struct {
+	char *id;
+	int type;
+} i8xx[] = {
+/* I810STR */		{ "7121", I810 },
+/* I810ESTR */		{ "7123", I810 },
+/* I810_DC100STR_1 */	{ "7125", I810 },
+/* I810_DC100STR_2 */	{ "1102", I810 },
+/* I810_IGSTR */	{ "1112", I810 },
+/* I810_CFCSTR */	{ "1132", I810 },
+/* I830STR */		{ "3577", I830 },
+/* I845STR */		{ "2562", I855 },
+/* I855STR */		{ "3582", I855 },
+/* I865STR		{ "2572", I865 }, */
+/* I915STR */		{ "2592", I915 },
+			{ NULL, 0 },
+};
+
+#ifdef __NetBSD__
+#define NONPRSTR		"32-bit nonprefetchable memory"
+#define MEMSTR			"base:"
+#else
 #define NONPRSTR		"32-bit, non-prefetchable"
+#define MEMSTR			"Memory at"
+#endif
 
 /* I810 registers */
 #define I810_HVSYNC		0x05000 
@@ -243,62 +260,48 @@ void probe_card_I830(struct i810_par *pa
 		i810_readl(par->mmio, I830_DSPBSTRIDE));
 }
 
-char *i810_chip(char **buff_ptr, int *len_ptr, FILE *pci_f, int* chiptype)
+char *i810_chip(char **buff_ptr, size_t *len_ptr, FILE *pci_f, int* chiptype)
 {
 	int i;
 	char *p;
+	char buf[10];
 
 	while (getline(buff_ptr, len_ptr, pci_f) > 0) {
-		i = (p = strstr(*buff_ptr, I810STR)) != NULL ||
-			(p = strstr(*buff_ptr, I810ESTR)) != NULL ||
-			(p = strstr(*buff_ptr, I810_DC100STR_1)) != NULL ||
-			(p = strstr(*buff_ptr, I810_DC100STR_2)) != NULL ||
-			(p = strstr(*buff_ptr, I810_IGSTR)) != NULL ||
-			(p = strstr(*buff_ptr, I810_CFCSTR)) != NULL;
-		if (i)
-		{
-			*chiptype = I810;
-			return p;
-		}
-
-		i = (p = strstr(*buff_ptr, I830STR)) != NULL ||
-#if defined (I865STR)
-			(p = strstr(*buff_ptr, I865STR)) != NULL ||
-#endif /*defined (I865STR)*/
-			(p = strstr(*buff_ptr, I845STR)) != NULL;
-		if (i)
-		{
-			*chiptype = I830;
-			return p;
-		}
-
-		i = (p = strstr(*buff_ptr, I855STR)) != NULL;
-		if (i)
-		{
-			*chiptype = I855;
-			return p;
-		}
-
-		i = (p = strstr(*buff_ptr, I915STR)) != NULL;
-		if (i)
-		{
-			*chiptype = I915;
+		for (i = 0; i8xx[i].id != NULL; i++) {
+#ifdef __NetBSD__
+			snprintf(buf, sizeof(buf), "%s8086", i8xx[i].id);
+#else
+			snprintf(buf, sizeof(buf), "8086:%s", i8xx[i].id);
+#endif
+			if ((p = strstr(*buff_ptr, buf)) != NULL)
+				break;
+		}
+		if (i8xx[i].id) {
+			*chiptype = i8xx[i].type;
+#ifdef __NetBSD__
+			return *buff_ptr;
+#else
 			return p;
+#endif
 		}
 	}
 	return NULL;
 }
 
-unsigned long i810_addr(char **buff_ptr, int *len_ptr, FILE *pci_f)
+unsigned long i810_addr(char **buff_ptr, size_t *len_ptr, FILE *pci_f)
 {
 	char *p;
 
-	while (getline(buff_ptr, len_ptr, pci_f) > 0)
+	while (getline(buff_ptr, len_ptr, pci_f) > 0) {
 		if (strstr(*buff_ptr, NONPRSTR) != NULL) {
+#ifdef __NetBSD__
+			assert(getline(buff_ptr, len_ptr, pci_f) > 0);
+#endif
 			p = strstr(*buff_ptr, MEMSTR);
 			if (p != NULL)
 				return strtoul(p+sizeof(MEMSTR), NULL, 16);
 		}
+	}
 	return 0;
 }
 
@@ -316,10 +319,15 @@ int main (int argc, char *argv[])
 {
 	struct i810_par par;
 	unsigned long addr;
-	int i, crt = -1, lcd = -1, probe = 0, err = 0, count = 0, chiptype, len = 0;
+	int i, crt = -1, lcd = -1, probe = 0, err = 0, count = 0, chiptype;
+	size_t len = 0;
 	FILE *pci_f;
 	char *buff = NULL;
+#ifdef __NetBSD__
+	char lspcistr[] = CMD_LSPCI " dump -d %d -f %d";
+#else
 	char lspcistr[] = CMD_LSPCI " -v -d xxxx:xxxx";
+#endif
 	char *chip;
 
 	putenv("PATH=/sbin:/usr/sbin:/bin:/usr/bin");
@@ -357,7 +365,11 @@ int main (int argc, char *argv[])
 		}
 	}
 
-	pci_f = popen(CMD_LSPCI " -n", "r");
+	pci_f = popen(CMD_LSPCI 
+#ifdef __NetBSD__
+			" list"
+#endif
+			" -n", "r");
 	if (!pci_f) {
 		fprintf(stderr, "Something is wrong with lspci.\n");
 		exit(1);
@@ -369,6 +381,19 @@ int main (int argc, char *argv[])
 	}
 	pclose(pci_f);
 
+#ifdef __NetBSD__
+	{
+		char cmd[100];
+		int dev = -1, fun = -1;
+		sscanf(chip, "000:%d:%d:", &dev, &fun);
+		if (dev == -1 || fun == -1) {
+			fprintf(stderr, "CMD_LSPCI is wrong.\n");
+			exit(1);
+		}
+		snprintf(cmd, sizeof(cmd), lspcistr, dev, fun);
+		pci_f = popen(cmd, "r");
+	}
+#else
 	{
 		char *p = strstr(lspcistr, "xxxx:xxxx");
 		if (p == 0) {
@@ -376,9 +401,10 @@ int main (int argc, char *argv[])
 			exit(1);
 		}
 		memcpy(p, chip, 9);
+		pci_f = popen(lspcistr, "r");
 	}
+#endif
 
-	pci_f = popen(lspcistr, "r");
 	if (!pci_f) {
 		fprintf(stderr, "Something is wrong with lspci.\n");
 		exit(1);