Lines 133-151
linsysfs_link_scsi_host(PFS_FILL_ARGS)
Link Here
|
133 |
return (0); |
133 |
return (0); |
134 |
} |
134 |
} |
135 |
|
135 |
|
136 |
#define PCI_DEV "pci" |
|
|
137 |
static int |
136 |
static int |
138 |
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char *path, |
137 |
linsysfs_fill_data(PFS_FILL_ARGS) |
139 |
char *prefix) |
138 |
{ |
|
|
139 |
sbuf_printf(sb, "%s", pn->pn_data); |
140 |
return (0); |
141 |
} |
142 |
|
143 |
static int |
144 |
linsysfs_fill_vendor(PFS_FILL_ARGS) |
145 |
{ |
146 |
sbuf_printf(sb, "0x%04x\n", pci_get_vendor((device_t)pn->pn_data)); |
147 |
return (0); |
148 |
} |
149 |
|
150 |
static int |
151 |
linsysfs_fill_device(PFS_FILL_ARGS) |
152 |
{ |
153 |
sbuf_printf(sb, "0x%04x\n", pci_get_device((device_t)pn->pn_data)); |
154 |
return (0); |
155 |
} |
156 |
|
157 |
static int |
158 |
linsysfs_fill_subvendor(PFS_FILL_ARGS) |
159 |
{ |
160 |
sbuf_printf(sb, "0x%04x\n", pci_get_subvendor((device_t)pn->pn_data)); |
161 |
return (0); |
162 |
} |
163 |
|
164 |
static int |
165 |
linsysfs_fill_subdevice(PFS_FILL_ARGS) |
166 |
{ |
167 |
sbuf_printf(sb, "0x%04x\n", pci_get_subdevice((device_t)pn->pn_data)); |
168 |
return (0); |
169 |
} |
170 |
|
171 |
static int |
172 |
linsysfs_fill_revid(PFS_FILL_ARGS) |
173 |
{ |
174 |
sbuf_printf(sb, "0x%x\n", pci_get_revid((device_t)pn->pn_data)); |
175 |
return (0); |
176 |
} |
177 |
|
178 |
/* |
179 |
* Filler function for PCI uevent file |
180 |
*/ |
181 |
static int |
182 |
linsysfs_fill_uevent_pci(PFS_FILL_ARGS) |
183 |
{ |
184 |
device_t dev = (device_t)pn->pn_data; |
185 |
sbuf_printf(sb, "DRIVER=%s\nPCI_CLASS=%X\nPCI_ID=%04X:%04X\n" |
186 |
"PCI_SUBSYS_ID=%04X:%04X\nPCI_SLOT_NAME=%04d:%02x:%02x.%x\n", |
187 |
linux_driver_get_name_dev(dev), |
188 |
pci_get_class(dev), |
189 |
pci_get_vendor(dev), pci_get_device(dev), |
190 |
pci_get_subvendor(dev), pci_get_subdevice(dev), |
191 |
pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)); |
192 |
return (0); |
193 |
} |
194 |
|
195 |
/* |
196 |
* Filler function for drm uevent file |
197 |
*/ |
198 |
static int |
199 |
linsysfs_fill_uevent_drm(PFS_FILL_ARGS) |
200 |
{ |
201 |
device_t dev = (device_t)pn->pn_data; |
202 |
int unit = device_get_unit(dev); |
203 |
sbuf_printf(sb, "MAJOR=226\nMINOR=%d\nDEVNAME=drm/%d\nDEVTYPE=dri_minor\n", |
204 |
unit, unit); |
205 |
return (0); |
206 |
} |
207 |
|
208 |
|
209 |
/* |
210 |
* Filler function for symlink from drm char device to PCI device |
211 |
*/ |
212 |
static int |
213 |
linsysfs_fill_vgapci(PFS_FILL_ARGS) |
214 |
{ |
215 |
struct pfs_node *cur = (struct pfs_node*)pn->pn_data; |
216 |
char *temp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); |
217 |
char *path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); |
218 |
path[0] = '\0'; |
219 |
do { |
220 |
snprintf(temp, MAXPATHLEN, "%s/%s", cur->pn_name, path); |
221 |
strlcpy(path, temp, MAXPATHLEN); |
222 |
cur = cur->pn_parent; |
223 |
} while (cur->pn_parent); |
224 |
path[strnlen(path, MAXPATHLEN) - 1] = '\0'; /* remove extra slash */ |
225 |
sbuf_printf(sb, "../../../%s", path); |
226 |
free(path, M_TEMP); |
227 |
free(temp, M_TEMP); |
228 |
return (0); |
229 |
} |
230 |
|
231 |
#define PCI_DEV "pci" |
232 |
#define DRMN_DEV "drmn" |
233 |
static int |
234 |
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, struct pfs_node *chardev, |
235 |
char *path, char *prefix) |
140 |
{ |
236 |
{ |
141 |
struct scsi_host_queue *scsi_host; |
237 |
struct scsi_host_queue *scsi_host; |
142 |
struct pfs_node *sub_dir; |
238 |
struct pfs_node *sub_dir, *cur_file, *cur_chardev; |
143 |
int i, nchildren; |
239 |
int i, nchildren; |
144 |
device_t *children, parent; |
240 |
device_t *children, parent; |
145 |
devclass_t devclass; |
241 |
devclass_t devclass; |
146 |
const char *name = NULL; |
242 |
const char *name = NULL; |
147 |
struct pci_devinfo *dinfo; |
243 |
struct pci_devinfo *dinfo = NULL; |
148 |
char *device, *host, *new_path = path; |
244 |
char *device, *host, *new_path = path, *chardevname = malloc(16, M_TEMP, M_WAITOK); |
149 |
|
245 |
|
150 |
parent = device_get_parent(dev); |
246 |
parent = device_get_parent(dev); |
151 |
if (parent) { |
247 |
if (parent) { |
Lines 171-176
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char
Link Here
|
171 |
strcat(new_path, device); |
267 |
strcat(new_path, device); |
172 |
dir = pfs_create_dir(dir, device, |
268 |
dir = pfs_create_dir(dir, device, |
173 |
NULL, NULL, NULL, 0); |
269 |
NULL, NULL, NULL, 0); |
|
|
270 |
cur_file = pfs_create_file(dir, "vendor", |
271 |
&linsysfs_fill_vendor, NULL, NULL, NULL, PFS_RD); |
272 |
cur_file->pn_data = (void*)dev; |
273 |
cur_file = pfs_create_file(dir, "device", |
274 |
&linsysfs_fill_device, NULL, NULL, NULL, PFS_RD); |
275 |
cur_file->pn_data = (void*)dev; |
276 |
cur_file = pfs_create_file(dir, "subsystem_vendor", |
277 |
&linsysfs_fill_subvendor, NULL, NULL, NULL, PFS_RD); |
278 |
cur_file->pn_data = (void*)dev; |
279 |
cur_file = pfs_create_file(dir, "subsystem_device", |
280 |
&linsysfs_fill_subdevice, NULL, NULL, NULL, PFS_RD); |
281 |
cur_file->pn_data = (void*)dev; |
282 |
cur_file = pfs_create_file(dir, "revision", |
283 |
&linsysfs_fill_revid, NULL, NULL, NULL, PFS_RD); |
284 |
cur_file->pn_data = (void*)dev; |
285 |
cur_file = pfs_create_file(dir, "uevent", |
286 |
&linsysfs_fill_uevent_pci, NULL, NULL, NULL, PFS_RD); |
287 |
cur_file->pn_data = (void*)dev; |
288 |
cur_file = pfs_create_link(dir, "subsystem", |
289 |
&linsysfs_fill_data, NULL, NULL, NULL, 0); |
290 |
/* libdrm just checks that the link ends in "/pci" */ |
291 |
cur_file->pn_data = "/sys/bus/pci"; |
174 |
|
292 |
|
175 |
if (dinfo->cfg.baseclass == PCIC_STORAGE) { |
293 |
if (dinfo->cfg.baseclass == PCIC_STORAGE) { |
176 |
/* DJA only make this if needed */ |
294 |
/* DJA only make this if needed */ |
Lines 207-221
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char
Link Here
|
207 |
free(host, M_TEMP); |
325 |
free(host, M_TEMP); |
208 |
} |
326 |
} |
209 |
} |
327 |
} |
|
|
328 |
|
329 |
dinfo = device_get_ivars(parent); |
330 |
if (dinfo && dinfo->cfg.baseclass == PCIC_DISPLAY) { |
331 |
devclass = device_get_devclass(dev); |
332 |
if (devclass != NULL) |
333 |
name = devclass_get_name(devclass); |
334 |
if (name && strcmp(name, DRMN_DEV) == 0 && device_get_unit(dev) >= 0) { |
335 |
sprintf(chardevname, "226:%d", device_get_unit(dev)); |
336 |
cur_chardev = pfs_create_dir(chardev, chardevname, NULL, NULL, NULL, 0); |
337 |
cur_file = pfs_create_link(cur_chardev, "device", &linsysfs_fill_vgapci, |
338 |
NULL, NULL, NULL, PFS_RD); |
339 |
cur_file->pn_data = (void*)dir; |
340 |
cur_file = pfs_create_file(cur_chardev, "uevent", &linsysfs_fill_uevent_drm, |
341 |
NULL, NULL, NULL, PFS_RD); |
342 |
cur_file->pn_data = (void*)dev; |
343 |
} |
344 |
} |
210 |
} |
345 |
} |
211 |
|
346 |
|
212 |
device_get_children(dev, &children, &nchildren); |
347 |
device_get_children(dev, &children, &nchildren); |
213 |
for (i = 0; i < nchildren; i++) { |
348 |
for (i = 0; i < nchildren; i++) { |
214 |
if (children[i]) |
349 |
if (children[i]) |
215 |
linsysfs_run_bus(children[i], dir, scsi, new_path, prefix); |
350 |
linsysfs_run_bus(children[i], dir, scsi, chardev, new_path, prefix); |
216 |
} |
351 |
} |
217 |
if (new_path != path) |
352 |
if (new_path != path) |
218 |
free(new_path, M_TEMP); |
353 |
free(new_path, M_TEMP); |
|
|
354 |
free(chardevname, M_TEMP); |
219 |
|
355 |
|
220 |
return (1); |
356 |
return (1); |
221 |
} |
357 |
} |
Lines 279-284
linsysfs_init(PFS_INIT_ARGS)
Link Here
|
279 |
struct pfs_node *dir, *sys, *cpu; |
415 |
struct pfs_node *dir, *sys, *cpu; |
280 |
struct pfs_node *pci; |
416 |
struct pfs_node *pci; |
281 |
struct pfs_node *scsi; |
417 |
struct pfs_node *scsi; |
|
|
418 |
struct pfs_node *devdir, *chardev; |
282 |
devclass_t devclass; |
419 |
devclass_t devclass; |
283 |
device_t dev; |
420 |
device_t dev; |
284 |
|
421 |
|
Lines 296-308
linsysfs_init(PFS_INIT_ARGS)
Link Here
|
296 |
/* /sys/devices/pci0000:00 */ |
433 |
/* /sys/devices/pci0000:00 */ |
297 |
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); |
434 |
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); |
298 |
|
435 |
|
|
|
436 |
/* /sys/dev/char */ |
437 |
devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0); |
438 |
chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0); |
439 |
|
299 |
devclass = devclass_find("root"); |
440 |
devclass = devclass_find("root"); |
300 |
if (devclass == NULL) { |
441 |
if (devclass == NULL) { |
301 |
return (0); |
442 |
return (0); |
302 |
} |
443 |
} |
303 |
|
444 |
|
304 |
dev = devclass_get_device(devclass, 0); |
445 |
dev = devclass_get_device(devclass, 0); |
305 |
linsysfs_run_bus(dev, pci, scsi, "/pci0000:00", "0000"); |
446 |
linsysfs_run_bus(dev, pci, scsi, chardev, "/pci0000:00", "0000"); |
306 |
|
447 |
|
307 |
/* /sys/devices/system */ |
448 |
/* /sys/devices/system */ |
308 |
sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0); |
449 |
sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0); |