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" |
136 |
/* |
|
|
137 |
* Filler function for custom strings |
138 |
*/ |
137 |
static int |
139 |
static int |
138 |
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, char *path, |
140 |
linsysfs_fill_data(PFS_FILL_ARGS) |
139 |
char *prefix) |
141 |
{ |
|
|
142 |
sbuf_printf(sb, "%s", pn->pn_data); |
143 |
return (0); |
144 |
} |
145 |
|
146 |
/* |
147 |
* Filler function for PCI vendor |
148 |
*/ |
149 |
static int |
150 |
linsysfs_fill_vendor(PFS_FILL_ARGS) |
151 |
{ |
152 |
sbuf_printf(sb, "0x%04x\n", pci_get_vendor((device_t)pn->pn_data)); |
153 |
return (0); |
154 |
} |
155 |
|
156 |
/* |
157 |
* Filler function for PCI device |
158 |
*/ |
159 |
static int |
160 |
linsysfs_fill_device(PFS_FILL_ARGS) |
161 |
{ |
162 |
sbuf_printf(sb, "0x%04x\n", pci_get_device((device_t)pn->pn_data)); |
163 |
return (0); |
164 |
} |
165 |
|
166 |
/* |
167 |
* Filler function for PCI subvendor |
168 |
*/ |
169 |
static int |
170 |
linsysfs_fill_subvendor(PFS_FILL_ARGS) |
171 |
{ |
172 |
sbuf_printf(sb, "0x%04x\n", pci_get_subvendor((device_t)pn->pn_data)); |
173 |
return (0); |
174 |
} |
175 |
|
176 |
/* |
177 |
* Filler function for PCI subdevice |
178 |
*/ |
179 |
static int |
180 |
linsysfs_fill_subdevice(PFS_FILL_ARGS) |
181 |
{ |
182 |
sbuf_printf(sb, "0x%04x\n", pci_get_subdevice((device_t)pn->pn_data)); |
183 |
return (0); |
184 |
} |
185 |
|
186 |
/* |
187 |
* Filler function for PCI revid |
188 |
*/ |
189 |
static int |
190 |
linsysfs_fill_revid(PFS_FILL_ARGS) |
191 |
{ |
192 |
sbuf_printf(sb, "0x%x\n", pci_get_revid((device_t)pn->pn_data)); |
193 |
return (0); |
194 |
} |
195 |
|
196 |
/* |
197 |
* Filler function for PCI uevent |
198 |
*/ |
199 |
static int |
200 |
linsysfs_fill_uevent_pci(PFS_FILL_ARGS) |
201 |
{ |
202 |
device_t dev = (device_t)pn->pn_data; |
203 |
sbuf_printf(sb, "DRIVER=%s\nPCI_CLASS=%X\nPCI_ID=%04X:%04X\n" |
204 |
"PCI_SUBSYS_ID=%04X:%04X\nPCI_SLOT_NAME=%04d:%02x:%02x.%x\n", |
205 |
linux_driver_get_name_dev(dev), |
206 |
pci_get_class(dev), |
207 |
pci_get_vendor(dev), pci_get_device(dev), |
208 |
pci_get_subvendor(dev), pci_get_subdevice(dev), |
209 |
pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)); |
210 |
return (0); |
211 |
} |
212 |
|
213 |
/* |
214 |
* Filler function for drm uevent |
215 |
*/ |
216 |
static int |
217 |
linsysfs_fill_uevent_drm(PFS_FILL_ARGS) |
218 |
{ |
219 |
device_t dev = (device_t)pn->pn_data; |
220 |
int unit = device_get_unit(dev); |
221 |
sbuf_printf(sb, "MAJOR=226\nMINOR=%d\nDEVNAME=drm/%d\nDEVTYPE=dri_minor\n", |
222 |
unit, unit); |
223 |
return (0); |
224 |
} |
225 |
|
226 |
|
227 |
/* |
228 |
* Filler function for symlink from drm char device to PCI device |
229 |
*/ |
230 |
static int |
231 |
linsysfs_fill_vgapci(PFS_FILL_ARGS) |
232 |
{ |
233 |
struct pfs_node *cur = (struct pfs_node*)pn->pn_data; |
234 |
char *temp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); |
235 |
char *path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); |
236 |
path[0] = '\0'; |
237 |
do { |
238 |
snprintf(temp, MAXPATHLEN, "%s/%s", cur->pn_name, path); |
239 |
strncpy(path, temp, MAXPATHLEN); |
240 |
cur = cur->pn_parent; |
241 |
} while (cur->pn_parent); |
242 |
path[strnlen(path, MAXPATHLEN) - 1] = '\0'; /* remove extra slash */ |
243 |
sbuf_printf(sb, "../../../%s", path); |
244 |
free(path, M_TEMP); |
245 |
free(temp, M_TEMP); |
246 |
return (0); |
247 |
} |
248 |
|
249 |
#define PCI_DEV "pci" |
250 |
#define DRMN_DEV "drmn" |
251 |
static int |
252 |
linsysfs_run_bus(device_t dev, struct pfs_node *dir, struct pfs_node *scsi, struct pfs_node *chardev, |
253 |
char *path, char *prefix) |
140 |
{ |
254 |
{ |
141 |
struct scsi_host_queue *scsi_host; |
255 |
struct scsi_host_queue *scsi_host; |
142 |
struct pfs_node *sub_dir; |
256 |
struct pfs_node *sub_dir, *cur_file, *cur_chardev; |
143 |
int i, nchildren; |
257 |
int i, nchildren; |
144 |
device_t *children, parent; |
258 |
device_t *children, parent; |
145 |
devclass_t devclass; |
259 |
devclass_t devclass; |
146 |
const char *name = NULL; |
260 |
const char *name = NULL; |
147 |
struct pci_devinfo *dinfo; |
261 |
struct pci_devinfo *dinfo = NULL; |
148 |
char *device, *host, *new_path = path; |
262 |
char *device, *host, *new_path = path, *chardevname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); |
149 |
|
263 |
|
150 |
parent = device_get_parent(dev); |
264 |
parent = device_get_parent(dev); |
151 |
if (parent) { |
265 |
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); |
285 |
strcat(new_path, device); |
172 |
dir = pfs_create_dir(dir, device, |
286 |
dir = pfs_create_dir(dir, device, |
173 |
NULL, NULL, NULL, 0); |
287 |
NULL, NULL, NULL, 0); |
|
|
288 |
cur_file = pfs_create_file(dir, "vendor", |
289 |
&linsysfs_fill_vendor, NULL, NULL, NULL, PFS_RD); |
290 |
cur_file->pn_data = (void*)dev; |
291 |
cur_file = pfs_create_file(dir, "device", |
292 |
&linsysfs_fill_device, NULL, NULL, NULL, PFS_RD); |
293 |
cur_file->pn_data = (void*)dev; |
294 |
cur_file = pfs_create_file(dir, "subsystem_vendor", |
295 |
&linsysfs_fill_subvendor, NULL, NULL, NULL, PFS_RD); |
296 |
cur_file->pn_data = (void*)dev; |
297 |
cur_file = pfs_create_file(dir, "subsystem_device", |
298 |
&linsysfs_fill_subdevice, NULL, NULL, NULL, PFS_RD); |
299 |
cur_file->pn_data = (void*)dev; |
300 |
cur_file = pfs_create_file(dir, "revision", |
301 |
&linsysfs_fill_revid, NULL, NULL, NULL, PFS_RD); |
302 |
cur_file->pn_data = (void*)dev; |
303 |
cur_file = pfs_create_file(dir, "uevent", |
304 |
&linsysfs_fill_uevent_pci, NULL, NULL, NULL, PFS_RD); |
305 |
cur_file->pn_data = (void*)dev; |
306 |
cur_file = pfs_create_link(dir, "subsystem", |
307 |
&linsysfs_fill_data, NULL, NULL, NULL, 0); |
308 |
/* libdrm just checks that the link ends in "/pci" */ |
309 |
cur_file->pn_data = "/sys/bus/pci"; |
174 |
|
310 |
|
175 |
if (dinfo->cfg.baseclass == PCIC_STORAGE) { |
311 |
if (dinfo->cfg.baseclass == PCIC_STORAGE) { |
176 |
/* DJA only make this if needed */ |
312 |
/* 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); |
343 |
free(host, M_TEMP); |
208 |
} |
344 |
} |
209 |
} |
345 |
} |
|
|
346 |
|
347 |
dinfo = device_get_ivars(parent); |
348 |
if (dinfo && dinfo->cfg.baseclass == PCIC_DISPLAY) { |
349 |
devclass = device_get_devclass(dev); |
350 |
if (devclass != NULL) |
351 |
name = devclass_get_name(devclass); |
352 |
if (name && strcmp(name, DRMN_DEV) == 0 && device_get_unit(dev) >= 0) { |
353 |
sprintf(chardevname, "226:%d", device_get_unit(dev)); |
354 |
cur_chardev = pfs_create_dir(chardev, chardevname, NULL, NULL, NULL, 0); |
355 |
cur_file = pfs_create_link(cur_chardev, "device", &linsysfs_fill_vgapci, |
356 |
NULL, NULL, NULL, PFS_RD); |
357 |
cur_file->pn_data = (void*)dir; |
358 |
cur_file = pfs_create_file(cur_chardev, "uevent", &linsysfs_fill_uevent_drm, |
359 |
NULL, NULL, NULL, PFS_RD); |
360 |
cur_file->pn_data = (void*)dev; |
361 |
} |
362 |
} |
210 |
} |
363 |
} |
211 |
|
364 |
|
212 |
device_get_children(dev, &children, &nchildren); |
365 |
device_get_children(dev, &children, &nchildren); |
213 |
for (i = 0; i < nchildren; i++) { |
366 |
for (i = 0; i < nchildren; i++) { |
214 |
if (children[i]) |
367 |
if (children[i]) |
215 |
linsysfs_run_bus(children[i], dir, scsi, new_path, prefix); |
368 |
linsysfs_run_bus(children[i], dir, scsi, chardev, new_path, prefix); |
216 |
} |
369 |
} |
217 |
if (new_path != path) |
370 |
if (new_path != path) |
218 |
free(new_path, M_TEMP); |
371 |
free(new_path, M_TEMP); |
|
|
372 |
free(chardevname, M_TEMP); |
219 |
|
373 |
|
220 |
return (1); |
374 |
return (1); |
221 |
} |
375 |
} |
Lines 279-284
linsysfs_init(PFS_INIT_ARGS)
Link Here
|
279 |
struct pfs_node *dir, *sys, *cpu; |
433 |
struct pfs_node *dir, *sys, *cpu; |
280 |
struct pfs_node *pci; |
434 |
struct pfs_node *pci; |
281 |
struct pfs_node *scsi; |
435 |
struct pfs_node *scsi; |
|
|
436 |
struct pfs_node *devdir, *chardev; |
282 |
devclass_t devclass; |
437 |
devclass_t devclass; |
283 |
device_t dev; |
438 |
device_t dev; |
284 |
|
439 |
|
Lines 296-308
linsysfs_init(PFS_INIT_ARGS)
Link Here
|
296 |
/* /sys/devices/pci0000:00 */ |
451 |
/* /sys/devices/pci0000:00 */ |
297 |
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); |
452 |
pci = pfs_create_dir(dir, "pci0000:00", NULL, NULL, NULL, 0); |
298 |
|
453 |
|
|
|
454 |
/* /sys/dev/char */ |
455 |
devdir = pfs_create_dir(root, "dev", NULL, NULL, NULL, 0); |
456 |
chardev = pfs_create_dir(devdir, "char", NULL, NULL, NULL, 0); |
457 |
|
299 |
devclass = devclass_find("root"); |
458 |
devclass = devclass_find("root"); |
300 |
if (devclass == NULL) { |
459 |
if (devclass == NULL) { |
301 |
return (0); |
460 |
return (0); |
302 |
} |
461 |
} |
303 |
|
462 |
|
304 |
dev = devclass_get_device(devclass, 0); |
463 |
dev = devclass_get_device(devclass, 0); |
305 |
linsysfs_run_bus(dev, pci, scsi, "/pci0000:00", "0000"); |
464 |
linsysfs_run_bus(dev, pci, scsi, chardev, "/pci0000:00", "0000"); |
306 |
|
465 |
|
307 |
/* /sys/devices/system */ |
466 |
/* /sys/devices/system */ |
308 |
sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0); |
467 |
sys = pfs_create_dir(dir, "system", NULL, NULL, NULL, 0); |