| @@ -1,34 +1,35 @@ | | | @@ -1,34 +1,35 @@ |
1 | $NetBSD: patch-ac,v 1.1 2006/12/04 04:42:03 christos Exp $ | | 1 | $NetBSD: patch-ac,v 1.2 2011/10/01 22:32:11 dholland Exp $ |
2 | --- i810switch.c 2005-06-12 00:36:36.000000000 -0400 | | 2 | |
3 | +++ i810switch.c 2006-12-03 23:12:44.000000000 -0500 | | 3 | --- i810switch.c.orig 2005-06-12 04:36:36.000000000 +0000 |
| | | 4 | +++ i810switch.c |
4 | @@ -1,3 +1,4 @@ | | 5 | @@ -1,3 +1,4 @@ |
5 | +#include <assert.h> | | 6 | +#include <assert.h> |
6 | #include <stdarg.h> | | 7 | #include <stdarg.h> |
7 | #include <stdlib.h> | | 8 | #include <stdlib.h> |
8 | #include <fcntl.h> | | 9 | #include <fcntl.h> |
9 | @@ -9,7 +10,11 @@ | | 10 | @@ -9,7 +10,11 @@ |
10 | #include <errno.h> | | 11 | #include <errno.h> |
11 | | | 12 | |
12 | #define VERSION "0.6.5beta" | | 13 | #define VERSION "0.6.5beta" |
13 | +#ifdef __NetBSD__ | | 14 | +#ifdef __NetBSD__ |
14 | +#define CMD_LSPCI "pcictl /dev/pci0" | | 15 | +#define CMD_LSPCI "pcictl /dev/pci0" |
15 | +#else | | 16 | +#else |
16 | #define CMD_LSPCI "lspci" | | 17 | #define CMD_LSPCI "lspci" |
17 | +#endif | | 18 | +#endif |
18 | | | 19 | |
19 | static const char *Opt_lcd = NULL; | | 20 | static const char *Opt_lcd = NULL; |
20 | static const char *Opt_crt = NULL; | | 21 | static const char *Opt_crt = NULL; |
21 | @@ -49,19 +54,31 @@ | | 22 | @@ -49,19 +54,31 @@ struct i810_par { |
22 | | | 23 | |
23 | | | 24 | |
24 | /* PCI IDs */ | | 25 | /* PCI IDs */ |
25 | -#define I810STR "8086:7121" | | 26 | -#define I810STR "8086:7121" |
26 | -#define I810ESTR "8086:7123" | | 27 | -#define I810ESTR "8086:7123" |
27 | -#define I810_DC100STR_1 "8086:7125" | | 28 | -#define I810_DC100STR_1 "8086:7125" |
28 | -#define I810_DC100STR_2 "8086:1102" | | 29 | -#define I810_DC100STR_2 "8086:1102" |
29 | -#define I810_IGSTR "8086:1112" | | 30 | -#define I810_IGSTR "8086:1112" |
30 | -#define I810_CFCSTR "8086:1132" | | 31 | -#define I810_CFCSTR "8086:1132" |
31 | -#define I830STR "8086:3577" | | 32 | -#define I830STR "8086:3577" |
32 | -#define I845STR "8086:2562" | | 33 | -#define I845STR "8086:2562" |
33 | -#define I855STR "8086:3582" | | 34 | -#define I855STR "8086:3582" |
34 | -//#define I865STR "8086:2572" | | 35 | -//#define I865STR "8086:2572" |
| @@ -52,27 +53,32 @@ $NetBSD: patch-ac,v 1.1 2006/12/04 04:42 | | | @@ -52,27 +53,32 @@ $NetBSD: patch-ac,v 1.1 2006/12/04 04:42 |
52 | + { NULL, 0 }, | | 53 | + { NULL, 0 }, |
53 | +}; | | 54 | +}; |
54 | + | | 55 | + |
55 | +#ifdef __NetBSD__ | | 56 | +#ifdef __NetBSD__ |
56 | +#define NONPRSTR "32-bit nonprefetchable memory" | | 57 | +#define NONPRSTR "32-bit nonprefetchable memory" |
57 | +#define MEMSTR "base:" | | 58 | +#define MEMSTR "base:" |
58 | +#else | | 59 | +#else |
59 | #define NONPRSTR "32-bit, non-prefetchable" | | 60 | #define NONPRSTR "32-bit, non-prefetchable" |
60 | +#define MEMSTR "Memory at" | | 61 | +#define MEMSTR "Memory at" |
61 | +#endif | | 62 | +#endif |
62 | | | 63 | |
63 | /* I810 registers */ | | 64 | /* I810 registers */ |
64 | #define I810_HVSYNC 0x05000 | | 65 | #define I810_HVSYNC 0x05000 |
65 | @@ -247,43 +264,25 @@ | | 66 | @@ -243,62 +260,48 @@ void probe_card_I830(struct i810_par *pa |
| | | 67 | i810_readl(par->mmio, I830_DSPBSTRIDE)); |
| | | 68 | } |
| | | 69 | |
| | | 70 | -char *i810_chip(char **buff_ptr, int *len_ptr, FILE *pci_f, int* chiptype) |
| | | 71 | +char *i810_chip(char **buff_ptr, size_t *len_ptr, FILE *pci_f, int* chiptype) |
66 | { | | 72 | { |
67 | int i; | | 73 | int i; |
68 | char *p; | | 74 | char *p; |
69 | + char buf[10]; | | 75 | + char buf[10]; |
70 | | | 76 | |
71 | while (getline(buff_ptr, len_ptr, pci_f) > 0) { | | 77 | while (getline(buff_ptr, len_ptr, pci_f) > 0) { |
72 | - i = (p = strstr(*buff_ptr, I810STR)) != NULL || | | 78 | - i = (p = strstr(*buff_ptr, I810STR)) != NULL || |
73 | - (p = strstr(*buff_ptr, I810ESTR)) != NULL || | | 79 | - (p = strstr(*buff_ptr, I810ESTR)) != NULL || |
74 | - (p = strstr(*buff_ptr, I810_DC100STR_1)) != NULL || | | 80 | - (p = strstr(*buff_ptr, I810_DC100STR_1)) != NULL || |
75 | - (p = strstr(*buff_ptr, I810_DC100STR_2)) != NULL || | | 81 | - (p = strstr(*buff_ptr, I810_DC100STR_2)) != NULL || |
76 | - (p = strstr(*buff_ptr, I810_IGSTR)) != NULL || | | 82 | - (p = strstr(*buff_ptr, I810_IGSTR)) != NULL || |
77 | - (p = strstr(*buff_ptr, I810_CFCSTR)) != NULL; | | 83 | - (p = strstr(*buff_ptr, I810_CFCSTR)) != NULL; |
78 | - if (i) | | 84 | - if (i) |
| @@ -112,96 +118,96 @@ $NetBSD: patch-ac,v 1.1 2006/12/04 04:42 | | | @@ -112,96 +118,96 @@ $NetBSD: patch-ac,v 1.1 2006/12/04 04:42 |
112 | + if ((p = strstr(*buff_ptr, buf)) != NULL) | | 118 | + if ((p = strstr(*buff_ptr, buf)) != NULL) |
113 | + break; | | 119 | + break; |
114 | + } | | 120 | + } |
115 | + if (i8xx[i].id) { | | 121 | + if (i8xx[i].id) { |
116 | + *chiptype = i8xx[i].type; | | 122 | + *chiptype = i8xx[i].type; |
117 | +#ifdef __NetBSD__ | | 123 | +#ifdef __NetBSD__ |
118 | + return *buff_ptr; | | 124 | + return *buff_ptr; |
119 | +#else | | 125 | +#else |
120 | return p; | | 126 | return p; |
121 | +#endif | | 127 | +#endif |
122 | } | | 128 | } |
123 | } | | 129 | } |
124 | return NULL; | | 130 | return NULL; |
125 | @@ -293,12 +292,16 @@ | | 131 | } |
| | | 132 | |
| | | 133 | -unsigned long i810_addr(char **buff_ptr, int *len_ptr, FILE *pci_f) |
| | | 134 | +unsigned long i810_addr(char **buff_ptr, size_t *len_ptr, FILE *pci_f) |
126 | { | | 135 | { |
127 | char *p; | | 136 | char *p; |
128 | | | 137 | |
129 | - while (getline(buff_ptr, len_ptr, pci_f) > 0) | | 138 | - while (getline(buff_ptr, len_ptr, pci_f) > 0) |
130 | + while (getline(buff_ptr, len_ptr, pci_f) > 0) { | | 139 | + while (getline(buff_ptr, len_ptr, pci_f) > 0) { |
131 | if (strstr(*buff_ptr, NONPRSTR) != NULL) { | | 140 | if (strstr(*buff_ptr, NONPRSTR) != NULL) { |
132 | +#ifdef __NetBSD__ | | 141 | +#ifdef __NetBSD__ |
133 | + assert(getline(buff_ptr, len_ptr, pci_f) > 0); | | 142 | + assert(getline(buff_ptr, len_ptr, pci_f) > 0); |
134 | +#endif | | 143 | +#endif |
135 | p = strstr(*buff_ptr, MEMSTR); | | 144 | p = strstr(*buff_ptr, MEMSTR); |
136 | if (p != NULL) | | 145 | if (p != NULL) |
137 | return strtoul(p+sizeof(MEMSTR), NULL, 16); | | 146 | return strtoul(p+sizeof(MEMSTR), NULL, 16); |
138 | } | | 147 | } |
139 | + } | | 148 | + } |
140 | return 0; | | 149 | return 0; |
141 | } | | 150 | } |
142 | | | 151 | |
143 | @@ -319,7 +322,11 @@ | | 152 | @@ -316,10 +319,15 @@ int main (int argc, char *argv[]) |
144 | int i, crt = -1, lcd = -1, probe = 0, err = 0, count = 0, chiptype, len = 0; | | 153 | { |
| | | 154 | struct i810_par par; |
| | | 155 | unsigned long addr; |
| | | 156 | - int i, crt = -1, lcd = -1, probe = 0, err = 0, count = 0, chiptype, len = 0; |
| | | 157 | + int i, crt = -1, lcd = -1, probe = 0, err = 0, count = 0, chiptype; |
| | | 158 | + size_t len = 0; |
145 | FILE *pci_f; | | 159 | FILE *pci_f; |
146 | char *buff = NULL; | | 160 | char *buff = NULL; |
147 | +#ifdef __NetBSD__ | | 161 | +#ifdef __NetBSD__ |
148 | + char lspcistr[] = CMD_LSPCI " dump -d %d -f %d"; | | 162 | + char lspcistr[] = CMD_LSPCI " dump -d %d -f %d"; |
149 | +#else | | 163 | +#else |
150 | char lspcistr[] = CMD_LSPCI " -v -d xxxx:xxxx"; | | 164 | char lspcistr[] = CMD_LSPCI " -v -d xxxx:xxxx"; |
151 | +#endif | | 165 | +#endif |
152 | char *chip; | | 166 | char *chip; |
153 | | | 167 | |
154 | putenv("PATH=/sbin:/usr/sbin:/bin:/usr/bin"); | | 168 | putenv("PATH=/sbin:/usr/sbin:/bin:/usr/bin"); |
155 | @@ -357,7 +364,11 @@ | | 169 | @@ -357,7 +365,11 @@ int main (int argc, char *argv[]) |
156 | } | | 170 | } |
157 | } | | 171 | } |
158 | | | 172 | |
159 | - pci_f = popen(CMD_LSPCI " -n", "r"); | | 173 | - pci_f = popen(CMD_LSPCI " -n", "r"); |
160 | + pci_f = popen(CMD_LSPCI | | 174 | + pci_f = popen(CMD_LSPCI |
161 | +#ifdef __NetBSD__ | | 175 | +#ifdef __NetBSD__ |
162 | + " list" | | 176 | + " list" |
163 | +#endif | | 177 | +#endif |
164 | + " -n", "r"); | | 178 | + " -n", "r"); |
165 | if (!pci_f) { | | 179 | if (!pci_f) { |
166 | fprintf(stderr, "Something is wrong with lspci.\n"); | | 180 | fprintf(stderr, "Something is wrong with lspci.\n"); |
167 | exit(1); | | 181 | exit(1); |
168 | @@ -369,6 +380,19 @@ | | 182 | @@ -369,6 +381,19 @@ int main (int argc, char *argv[]) |
169 | } | | 183 | } |
170 | pclose(pci_f); | | 184 | pclose(pci_f); |
171 | | | 185 | |
172 | +#ifdef __NetBSD__ | | 186 | +#ifdef __NetBSD__ |
173 | + { | | 187 | + { |
174 | + char cmd[100]; | | 188 | + char cmd[100]; |
175 | + int dev = -1, fun = -1; | | 189 | + int dev = -1, fun = -1; |
176 | + sscanf(chip, "000:%d:%d:", &dev, &fun); | | 190 | + sscanf(chip, "000:%d:%d:", &dev, &fun); |
177 | + if (dev == -1 || fun == -1) { | | 191 | + if (dev == -1 || fun == -1) { |
178 | + fprintf(stderr, "CMD_LSPCI is wrong.\n"); | | 192 | + fprintf(stderr, "CMD_LSPCI is wrong.\n"); |
179 | + exit(1); | | 193 | + exit(1); |
180 | + } | | 194 | + } |
181 | + snprintf(cmd, sizeof(cmd), lspcistr, dev, fun); | | 195 | + snprintf(cmd, sizeof(cmd), lspcistr, dev, fun); |
182 | + pci_f = popen(cmd, "r"); | | 196 | + pci_f = popen(cmd, "r"); |
183 | + } | | 197 | + } |
184 | +#else | | 198 | +#else |
185 | { | | 199 | { |
186 | char *p = strstr(lspcistr, "xxxx:xxxx"); | | 200 | char *p = strstr(lspcistr, "xxxx:xxxx"); |
187 | if (p == 0) { | | 201 | if (p == 0) { |
188 | @@ -376,16 +400,17 @@ | | 202 | @@ -376,9 +401,10 @@ int main (int argc, char *argv[]) |
189 | exit(1); | | 203 | exit(1); |
190 | } | | 204 | } |
191 | memcpy(p, chip, 9); | | 205 | memcpy(p, chip, 9); |
192 | + pci_f = popen(lspcistr, "r"); | | 206 | + pci_f = popen(lspcistr, "r"); |
193 | } | | 207 | } |
194 | +#endif | | 208 | +#endif |
195 | | | 209 | |
196 | - pci_f = popen(lspcistr, "r"); | | 210 | - pci_f = popen(lspcistr, "r"); |
197 | if (!pci_f) { | | 211 | if (!pci_f) { |
198 | fprintf(stderr, "Something is wrong with lspci.\n"); | | 212 | fprintf(stderr, "Something is wrong with lspci.\n"); |
199 | exit(1); | | 213 | exit(1); |
200 | } | | | |
201 | addr = i810_addr(&buff, &len, pci_f); | | | |
202 | if (addr == 0) { | | | |
203 | - fprintf(stderr, "Something is wrong with lspci.\n"); | | | |
204 | + fprintf(stderr, "Something is wrong with lspci.\n"); | | | |
205 | exit(1); | | | |
206 | } | | | |
207 | pclose(pci_f); | | | |