solx_devfs.c 32.9 KB
Newer Older
1
/*
Alan Coopersmith's avatar
Alan Coopersmith committed
2
 * (C) Copyright IBM Corporation 2006
3
 * Copyright (c) 2007, 2009, 2011, 2012, Oracle and/or its affiliates.
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
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/*
 * Solaris devfs interfaces
 */

#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/pci.h>
#include <libdevinfo.h>
#include "pci_tools.h"

41
42
43
44
45
#ifdef __x86
# include <sys/sysi86.h>
# include <sys/psw.h>
#endif

46
47
48
#include "pciaccess.h"
#include "pciaccess_private.h"

49
50
/* #define DEBUG */

51
#define	INITIAL_NUM_DEVICES	256
Alan Coopersmith's avatar
Alan Coopersmith committed
52
#define	CELL_NUMS_1275	(sizeof(pci_regspec_t) / sizeof(uint_t))
53

54
typedef union {
55
56
    uint8_t bytes[16 * sizeof (uint32_t)];
    uint32_t dwords[16];
57
58
59
} pci_conf_hdr_t;

typedef struct i_devnode {
60
61
62
63
    uint8_t bus;
    uint8_t dev;
    uint8_t func;
    di_node_t node;
64
65
66
} i_devnode_t;

typedef struct nexus {
67
    int fd;
68
69
    int first_bus;
    int last_bus;
70
    int domain;
71
    char *path;			/* for errors/debugging; fd is all we need */
72
    char *dev_path;
73
    struct nexus *next;
74
75
76
77
78
#ifdef __sparc
    struct pci_device **devlist;
    volatile size_t num_allocated_elems;
    volatile size_t num_devices;
#endif
79
} nexus_t;
80

81
82
83
84
85
86
typedef struct probe_info {
    volatile size_t num_allocated_elems;
    volatile size_t num_devices;
    struct pci_device_private * volatile devices;
} probe_info_t;

87
static nexus_t *nexus_list = NULL;
88
#if !defined(__sparc)
89
static int xsvc_fd = -1;
90
91
92
93
94
#endif

#ifdef __sparc
static di_prom_handle_t di_phdl;
#endif
95

96
97
98
99
100
101
102
/*
 * Read config space in native processor endianness.  Endian-neutral
 * processing can then take place.  On big endian machines, MSB and LSB
 * of little endian data end up switched if read as little endian.
 * They are in correct order if read as big endian.
 */
#if defined(__sparc)
103
# define NATIVE_ENDIAN	PCITOOL_ACC_ATTR_ENDN_BIG
104
#elif defined(__x86)
105
# define NATIVE_ENDIAN	PCITOOL_ACC_ATTR_ENDN_LTL
106
#else
107
# error "ISA is neither __sparc nor __x86"
108
109
#endif

110
111
112
113
#ifdef __sparc
#define MAPPING_DEV_PATH(dev)	 (((struct pci_device_private *) dev)->device_string)
#endif

114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Identify problematic southbridges.  These have device id 0x5249 and
 * vendor id 0x10b9.  Check for revision ID 0 and class code 060400 as well.
 * Values are little endian, so they are reversed for SPARC.
 *
 * Check for these southbridges on all architectures, as the issue is a
 * southbridge issue, independent of processor.
 *
 * If one of these is found during probing, skip probing other devs/funcs on
 * the rest of the bus, since the southbridge and all devs underneath will
 * otherwise disappear.
 */
#if (NATIVE_ENDIAN == PCITOOL_ACC_ATTR_ENDN_BIG)
127
128
# define U45_SB_DEVID_VID	0xb9104952
# define U45_SB_CLASS_RID	0x00000406
129
#else
130
131
# define U45_SB_DEVID_VID	0x524910b9
# define U45_SB_CLASS_RID	0x06040000
132
133
#endif

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifdef __sparc
static nexus_t *
find_nexus_for_dev(struct pci_device *dev)
{
    nexus_t *nexus;
    int i;

    for (nexus = nexus_list ; nexus != NULL ; nexus = nexus->next) {
	for (i = 0; i < nexus->num_devices; i++) {
	    if (nexus->devlist[i] == dev)
		return nexus;
	}
    }
    return NULL;
}
#else
150
static nexus_t *
151
find_nexus_for_bus( int domain, int bus )
152
{
153
    nexus_t *nexus;
154

155
    for (nexus = nexus_list ; nexus != NULL ; nexus = nexus->next) {
156
157
	if ((domain == nexus->domain) &&
	    (bus >= nexus->first_bus) && (bus <= nexus->last_bus)) {
158
	    return nexus;
159
	}
160
161
    }
    return NULL;
162
}
163
#endif
164

Alan Coopersmith's avatar
Alan Coopersmith committed
165
#define GET_CONFIG_VAL_8(offset) (config_hdr.bytes[offset])
166
#define GET_CONFIG_VAL_16(offset) \
Alan Coopersmith's avatar
Alan Coopersmith committed
167
    (uint16_t) (GET_CONFIG_VAL_8(offset) + (GET_CONFIG_VAL_8(offset+1) << 8))
168
#define GET_CONFIG_VAL_32(offset) \
Alan Coopersmith's avatar
Alan Coopersmith committed
169
170
171
172
    (uint32_t) (GET_CONFIG_VAL_8(offset) + 		\
		(GET_CONFIG_VAL_8(offset+1) << 8) +	\
		(GET_CONFIG_VAL_8(offset+2) << 16) +	\
		(GET_CONFIG_VAL_8(offset+3) << 24))
173

174
/*
175
 * Release all the resources
176
177
178
179
180
 * Solaris version
 */
static void
pci_system_solx_devfs_destroy( void )
{
181
    /*
Alan Coopersmith's avatar
Alan Coopersmith committed
182
183
184
     * The memory allocated for pci_sys & devices in create routines
     * will be freed in pci_system_cleanup.
     * Need to free system-specific allocations here.
185
186
187
188
189
190
     */
    nexus_t *nexus, *next;

    for (nexus = nexus_list ; nexus != NULL ; nexus = next) {
	next = nexus->next;
	close(nexus->fd);
191
	free(nexus->path);
192
	free(nexus->dev_path);
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifdef __sparc
	{
	    struct pci_device *dev;
	    int i;

	    for (i = 0; i < nexus->num_devices; i++) {
		dev = nexus->devlist[i];
		if (MAPPING_DEV_PATH(dev))
		    di_devfs_path_free((char *) MAPPING_DEV_PATH(dev));
	    }
	}
	free(nexus->devlist);
#endif
206
207
208
209
	free(nexus);
    }
    nexus_list = NULL;

210
211
212
213
#ifdef __sparc
    if (di_phdl != DI_PROM_HANDLE_NIL)
	(void) di_prom_fini(di_phdl);
#else
214
215
216
217
    if (xsvc_fd >= 0) {
	close(xsvc_fd);
	xsvc_fd = -1;
    }
218
#endif
219
}
220

221
222
223
224
225
226
/*
 * Retrieve first 16 dwords of device's config header, except for the first
 * dword.  First 16 dwords are defined by the PCI specification.
 */
static int
get_config_header(int fd, uint8_t bus_no, uint8_t dev_no, uint8_t func_no,
227
		  pci_conf_hdr_t *config_hdr_p)
228
{
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    pcitool_reg_t cfg_prg;
    int i;
    int rval = 0;

    /* Prepare a local pcitool_reg_t so as to not disturb the caller's. */
    cfg_prg.offset = 0;
    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
    cfg_prg.bus_no = bus_no;
    cfg_prg.dev_no = dev_no;
    cfg_prg.func_no = func_no;
    cfg_prg.barnum = 0;
    cfg_prg.user_version = PCITOOL_USER_VERSION;

    /* Get dwords 1-15 of config space. They must be read as uint32_t. */
    for (i = 1; i < (sizeof (pci_conf_hdr_t) / sizeof (uint32_t)); i++) {
	cfg_prg.offset += sizeof (uint32_t);
	if ((rval = ioctl(fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
	    break;
247
	}
248
249
	config_hdr_p->dwords[i] = (uint32_t)cfg_prg.data;
    }
250

251
    return (rval);
252
253
254
255
256
257
258
}


/*
 * Probe device's functions.  Modifies many fields in the prg_p.
 */
static int
259
probe_dev(nexus_t *nexus, pcitool_reg_t *prg_p, probe_info_t *pinfo)
260
{
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
    pci_conf_hdr_t	config_hdr;
    boolean_t		multi_function_device;
    int8_t		func;
    int8_t		first_func = 0;
    int8_t		last_func = PCI_REG_FUNC_M >> PCI_REG_FUNC_SHIFT;
    int			rval = 0;
    struct pci_device *	pci_base;

    /*
     * Loop through at least func=first_func.  Continue looping through
     * functions if there are no errors and the device is a multi-function
     * device.
     *
     * (Note, if first_func == 0, header will show whether multifunction
     * device and set multi_function_device.  If first_func != 0, then we
     * will force the loop as the user wants a specific function to be
     * checked.
     */
    for (func = first_func, multi_function_device = B_FALSE;
	 ((func <= last_func) &&
	  ((func == first_func) || (multi_function_device)));
	 func++) {
	prg_p->func_no = func;
284
285

	/*
286
287
288
289
290
291
292
293
294
295
	 * Four things can happen here:
	 *
	 * 1) ioctl comes back as EFAULT and prg_p->status is
	 *    PCITOOL_INVALID_ADDRESS.  There is no device at this location.
	 *
	 * 2) ioctl comes back successful and the data comes back as
	 *    zero.  Config space is mapped but no device responded.
	 *
	 * 3) ioctl comes back successful and the data comes back as
	 *    non-zero.  We've found a device.
296
	 *
297
	 * 4) Some other error occurs in an ioctl.
298
	 */
299
300
301
302
303
304

	prg_p->status = PCITOOL_SUCCESS;
	prg_p->offset = 0;
	prg_p->data = 0;
	prg_p->user_version = PCITOOL_USER_VERSION;

Alan Coopersmith's avatar
Alan Coopersmith committed
305
	errno = 0;
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
	if (((rval = ioctl(nexus->fd, PCITOOL_DEVICE_GET_REG, prg_p)) != 0) ||
	    (prg_p->data == 0xffffffff)) {

	    /*
	     * Accept errno == EINVAL along with status of
	     * PCITOOL_OUT_OF_RANGE because some systems
	     * don't implement the full range of config space.
	     * Leave the loop quietly in this case.
	     */
	    if ((errno == EINVAL) ||
		(prg_p->status == PCITOOL_OUT_OF_RANGE)) {
		break;
	    }

	    /*
	     * Exit silently with ENXIO as this means that there are
	     * no devices under the pci root nexus.
	     */
	    else if ((errno == ENXIO) &&
		     (prg_p->status == PCITOOL_IO_ERROR)) {
		break;
	    }

	    /*
	     * Expect errno == EFAULT along with status of
	     * PCITOOL_INVALID_ADDRESS because there won't be
	     * devices at each stop.  Quit on any other error.
	     */
	    else if (((errno != EFAULT) ||
		      (prg_p->status != PCITOOL_INVALID_ADDRESS)) &&
		     (prg_p->data != 0xffffffff)) {
337
338
339
340
#ifdef __sparc
/* on sparc, devices can be enumerated discontiguously. Do not quit */
		rval = 0;
#endif
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
		break;
	    }

	    /*
	     * If no function at this location,
	     * just advance to the next function.
	     */
	    else {
		rval = 0;
	    }

	    /*
	     * Data came back as 0.
	     * Treat as unresponsive device and check next device.
	     */
	} else if (prg_p->data == 0) {
	    rval = 0;
	    break;	/* Func loop. */

	    /* Found something. */
	} else {
	    config_hdr.dwords[0] = (uint32_t)prg_p->data;

	    /* Get the rest of the PCI header. */
	    if ((rval = get_config_header(nexus->fd, prg_p->bus_no,
					  prg_p->dev_no, prg_p->func_no,
					  &config_hdr)) != 0) {
		break;
	    }

	    /*
	     * Special case for the type of Southbridge found on
	     * Ultra-45 and other sun4u fire workstations.
	     */
	    if ((config_hdr.dwords[0] == U45_SB_DEVID_VID) &&
		(config_hdr.dwords[2] == U45_SB_CLASS_RID)) {
		rval = ECANCELED;
		break;
	    }

	    /*
	     * Found one device with bus number, device number and
	     * function number.
	     */

386
	    pci_base = &pinfo->devices[pinfo->num_devices].base;
387

388
	    pci_base->domain = nexus->domain;
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	    pci_base->bus = prg_p->bus_no;
	    pci_base->dev = prg_p->dev_no;
	    pci_base->func = func;

	    /*
	     * for the format of device_class, see struct pci_device;
	     */

	    pci_base->device_class =
		(GET_CONFIG_VAL_8(PCI_CONF_BASCLASS) << 16) |
		(GET_CONFIG_VAL_8(PCI_CONF_SUBCLASS) << 8) |
		GET_CONFIG_VAL_8(PCI_CONF_PROGCLASS);

	    pci_base->revision		= GET_CONFIG_VAL_8(PCI_CONF_REVID);
	    pci_base->vendor_id		= GET_CONFIG_VAL_16(PCI_CONF_VENID);
	    pci_base->device_id		= GET_CONFIG_VAL_16(PCI_CONF_DEVID);
	    pci_base->subvendor_id 	= GET_CONFIG_VAL_16(PCI_CONF_SUBVENID);
	    pci_base->subdevice_id 	= GET_CONFIG_VAL_16(PCI_CONF_SUBSYSID);
407
	    pci_base->irq		= GET_CONFIG_VAL_8(PCI_CONF_ILINE);
408

409
	    pinfo->devices[pinfo->num_devices].header_type
410
411
					= GET_CONFIG_VAL_8(PCI_CONF_HEADER);

412
413
414
415
#ifdef DEBUG
	    fprintf(stderr,
		    "nexus = %s, busno = %x, devno = %x, funcno = %x\n",
		    nexus->path, prg_p->bus_no, prg_p->dev_no, func);
416
417
#endif

418
419
420
421
422
423
424
425
426
	    pinfo->num_devices++;
	    if (pinfo->num_devices == pinfo->num_allocated_elems) {
		struct pci_device_private *new_devs;
		size_t new_num_elems = pinfo->num_allocated_elems * 2;

		new_devs = realloc(pinfo->devices,
			new_num_elems * sizeof (struct pci_device_private));
		if (new_devs == NULL) {
		    (void) fprintf(stderr,
427
428
429
			           "Error allocating memory for PCI devices:"
				   " %s\n discarding additional devices\n",
				   strerror(errno));
430
431
432
433
434
435
436
		    return (rval);
		}
		(void) memset(&new_devs[pinfo->num_devices], 0,
			pinfo->num_allocated_elems *
			sizeof (struct pci_device_private));
		pinfo->num_allocated_elems = new_num_elems;
		pinfo->devices = new_devs;
437
438
	    }

439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
#ifdef __sparc
	    nexus->devlist[nexus->num_devices++] = pci_base;

	    if (nexus->num_devices == nexus->num_allocated_elems) {
		struct pci_device **new_devs;
		size_t new_num_elems = nexus->num_allocated_elems * 2;

		new_devs = realloc(nexus->devlist,
			new_num_elems * sizeof (struct pci_device *));
		if (new_devs == NULL)
		    return (rval);
		(void) memset(&new_devs[nexus->num_devices], 0,
			nexus->num_allocated_elems *
			sizeof (struct pci_device *));
		nexus->num_allocated_elems = new_num_elems;
		nexus->devlist = new_devs;
	    }
#endif

458
459
460
461
462
463
464
465
466
	    /*
	     * Accommodate devices which state their
	     * multi-functionality only in their function 0 config
	     * space.  Note multi-functionality throughout probing
	     * of all of this device's functions.
	     */
	    if (config_hdr.bytes[PCI_CONF_HEADER] & PCI_HEADER_MULTI) {
		multi_function_device = B_TRUE;
	    }
467
	}
468
    }
469

470
    return (rval);
471
472
}

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

/*
 * Solaris version
 * Probe a given nexus config space for devices.
 *
 * fd is the file descriptor of the nexus.
 * input_args contains commandline options as specified by the user.
 */
static int
do_probe(nexus_t *nexus, probe_info_t *pinfo)
{
    pcitool_reg_t prg;
    uint32_t bus;
    uint8_t dev;
    uint32_t last_bus = nexus->last_bus;
    uint8_t last_dev = PCI_REG_DEV_M >> PCI_REG_DEV_SHIFT;
    uint8_t first_bus = nexus->first_bus;
    uint8_t first_dev = 0;
    int rval = 0;

    prg.barnum = 0;	/* Config space. */

    /* Must read in 4-byte quantities. */
    prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;

    prg.data = 0;

    /*
     * Loop through all valid bus / dev / func combinations to check for
     * all devices, with the following exceptions:
     *
     * When nothing is found at function 0 of a bus / dev combination, skip
     * the other functions of that bus / dev combination.
     *
     * When a found device's function 0 is probed and it is determined that
     * it is not a multifunction device, skip probing of that device's
     * other functions.
     */
    for (bus = first_bus; ((bus <= last_bus) && (rval == 0)); bus++) {
	prg.bus_no = (uint8_t)bus;

	for (dev = first_dev; ((dev <= last_dev) && (rval == 0)); dev++) {
	    prg.dev_no = dev;
	    rval = probe_dev(nexus, &prg, pinfo);
	}

	/*
	 * Ultra-45 southbridge workaround:
	 * ECANCELED tells to skip to the next bus.
	 */
	if (rval == ECANCELED) {
	    rval = 0;
	}
    }

    return (rval);
}

531
532
533
534
535
/*
 * This function is called from di_walk_minor() when any PROBE is processed
 */
static int
probe_nexus_node(di_node_t di_node, di_minor_t minor, void *arg)
536
{
537
538
    probe_info_t *pinfo = (probe_info_t *)arg;
    char *nexus_name, *nexus_dev_path;
539
540
541
542
    nexus_t *nexus;
    int fd;
    char nexus_path[MAXPATHLEN];

543
    di_prop_t prop;
544
    char *strings;
545
546
547
548
    int *ints;
    int numval;
    int pci_node = 0;
    int first_bus = 0, last_bus = PCI_REG_BUS_G(PCI_REG_BUS_M);
549
    int domain = 0;
550
551
552
553
554
555
#ifdef __sparc
    int bus_range_found = 0;
    int device_type_found = 0;
    di_prom_prop_t prom_prop;
#endif

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572

#ifdef DEBUG
    nexus_name = di_devfs_minor_path(minor);
    fprintf(stderr, "-- device name: %s\n", nexus_name);
#endif

    for (prop = di_prop_next(di_node, NULL); prop != NULL;
	 prop = di_prop_next(di_node, prop)) {

	const char *prop_name = di_prop_name(prop);

#ifdef DEBUG
	fprintf(stderr, "   property: %s\n", prop_name);
#endif

	if (strcmp(prop_name, "device_type") == 0) {
	    numval = di_prop_strings(prop, &strings);
573
574
575
576
577
578
579
580
581
582
	    if (numval == 1) {
		if (strncmp(strings, "pci", 3) != 0)
		    /* not a PCI node, bail */
		    return (DI_WALK_CONTINUE);
		else {
		    pci_node = 1;
#ifdef __sparc
		    device_type_found =  1;
#endif
		}
583
584
585
586
587
588
589
590
591
592
593
	    }
	}
	else if (strcmp(prop_name, "class-code") == 0) {
	    /* not a root bus node, bail */
	    return (DI_WALK_CONTINUE);
	}
	else if (strcmp(prop_name, "bus-range") == 0) {
	    numval = di_prop_ints(prop, &ints);
	    if (numval == 2) {
		first_bus = ints[0];
		last_bus = ints[1];
594
595
596
#ifdef __sparc
		bus_range_found = 1;
#endif
597
598
	    }
	}
599
600
601
602
603
604
	else if (strcmp(prop_name, "pciseg") == 0) {
	    numval = di_prop_ints(prop, &ints);
	    if (numval == 1) {
		domain = ints[0];
	    }
	}
605
606
    }

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
#ifdef __sparc
    if ((!device_type_found) && di_phdl) {
	numval = di_prom_prop_lookup_strings(di_phdl, di_node,
	    "device_type", &strings);
	if (numval == 1) {
	    if (strncmp(strings, "pci", 3) != 0)
		return (DI_WALK_CONTINUE);
	    else
		pci_node = 1;
	}
    }

    if ((!bus_range_found) && di_phdl) {
	numval = di_prom_prop_lookup_ints(di_phdl, di_node,
	    "bus-range", &ints);
	if (numval == 2) {
	    first_bus = ints[0];
	    last_bus = ints[1];
	}
    }
#endif

629
630
631
632
    if (pci_node != 1)
	return (DI_WALK_CONTINUE);

    /* we have a PCI root bus node. */
633
634
635
636
    nexus = calloc(1, sizeof(nexus_t));
    if (nexus == NULL) {
	(void) fprintf(stderr, "Error allocating memory for nexus: %s\n",
		       strerror(errno));
637
	return (DI_WALK_TERMINATE);
638
    }
639
640
    nexus->first_bus = first_bus;
    nexus->last_bus = last_bus;
641
    nexus->domain = domain;
642

643
644
645
646
647
648
649
650
651
652
653
654
#ifdef __sparc
    if ((nexus->devlist = calloc(INITIAL_NUM_DEVICES,
			sizeof (struct pci_device *))) == NULL) {
	(void) fprintf(stderr, "Error allocating memory for nexus devlist: %s\n",
                       strerror(errno));
	free (nexus);
	return (DI_WALK_TERMINATE);
    }
    nexus->num_allocated_elems = INITIAL_NUM_DEVICES;
    nexus->num_devices = 0;
#endif

655
656
657
658
659
660
661
662
663
    nexus_name = di_devfs_minor_path(minor);
    if (nexus_name == NULL) {
	(void) fprintf(stderr, "Error getting nexus path: %s\n",
		       strerror(errno));
	free(nexus);
	return (DI_WALK_CONTINUE);
    }

    snprintf(nexus_path, sizeof(nexus_path), "/devices%s", nexus_name);
Alan Coopersmith's avatar
Alan Coopersmith committed
664
    di_devfs_path_free(nexus_name);
665
666
667
668
669

#ifdef DEBUG
    fprintf(stderr, "nexus = %s, bus-range = %d - %d\n",
	    nexus_path, first_bus, last_bus);
#endif
670

671
    if ((fd = open(nexus_path, O_RDWR | O_CLOEXEC)) >= 0) {
672
	nexus->fd = fd;
673
	nexus->path = strdup(nexus_path);
674
675
676
677
	nexus_dev_path = di_devfs_path(di_node);
	nexus->dev_path = strdup(nexus_dev_path);
	di_devfs_path_free(nexus_dev_path);
	if ((do_probe(nexus, pinfo) != 0) && (errno != ENXIO)) {
678
679
680
	    (void) fprintf(stderr, "Error probing node %s: %s\n",
			   nexus_path, strerror(errno));
	    (void) close(fd);
681
	    free(nexus->path);
682
	    free(nexus->dev_path);
683
	    free(nexus);
684
	} else {
685
686
	    nexus->next = nexus_list;
	    nexus_list = nexus;
687
	}
688
689
690
691
692
693
694
    } else {
	(void) fprintf(stderr, "Error opening %s: %s\n",
		       nexus_path, strerror(errno));
	free(nexus);
    }

    return DI_WALK_CONTINUE;
695
696
}

697
698
699
static int
find_target_node(di_node_t node, void *arg)
{
700
701
702
    int *regbuf = NULL;
    int len = 0;
    uint32_t busno, funcno, devno;
703
    i_devnode_t *devnode = (i_devnode_t *)arg;
704
705
706
707
708

    /*
     * Test the property functions, only for testing
     */
    /*
709
710
    void *prop = DI_PROP_NIL;

711
712
    (void) fprintf(stderr, "start of node 0x%x\n", node->nodeid);
    while ((prop = di_prop_hw_next(node, prop)) != DI_PROP_NIL) {
713
	int i;
714
715
716
717
	(void) fprintf(stderr, "name=%s: ", di_prop_name(prop));
	len = 0;
	if (!strcmp(di_prop_name(prop), "reg")) {
	    len = di_prop_ints(prop, &regbuf);
718
	}
719
720
721
722
723
724
725
726
727
	for (i = 0; i < len; i++) {
	    fprintf(stderr, "0x%0x.", regbuf[i]);
	}
	fprintf(stderr, "\n");
    }
    (void) fprintf(stderr, "end of node 0x%x\n", node->nodeid);
    */

    len = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &regbuf);
728

729
730
731
732
733
#ifdef __sparc
    if ((len <= 0) && di_phdl)
	len = di_prom_prop_lookup_ints(di_phdl, node, "reg", &regbuf);
#endif

734
    if (len <= 0) {
735
#ifdef DEBUG
736
737
	fprintf(stderr, "error = %x\n", errno);
	fprintf(stderr, "can not find assigned-address\n");
738
739
#endif
	return (DI_WALK_CONTINUE);
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
    }

    busno = PCI_REG_BUS_G(regbuf[0]);
    devno = PCI_REG_DEV_G(regbuf[0]);
    funcno = PCI_REG_FUNC_G(regbuf[0]);

    if ((busno == devnode->bus) &&
	(devno == devnode->dev) &&
	(funcno == devnode->func)) {
	devnode->node = node;

	return (DI_WALK_TERMINATE);
    }

    return (DI_WALK_CONTINUE);
755
756
757
758
759
760
761
762
}

/*
 * Solaris version
 */
static int
pci_device_solx_devfs_probe( struct pci_device * dev )
{
763
    int err = 0;
764
765
    di_node_t rnode = DI_NODE_NIL;
    i_devnode_t args = { 0, 0, 0, DI_NODE_NIL };
766
767
768
769
    int *regbuf;
    pci_regspec_t *reg;
    int i;
    int len = 0;
770
    uint ent = 0;
771
772
    nexus_t *nexus;

773
774
775
#ifdef __sparc
    if ( (nexus = find_nexus_for_dev(dev)) == NULL )
#else
776
    if ( (nexus = find_nexus_for_bus(dev->domain, dev->bus)) == NULL )
777
#endif
778
	return ENODEV;
779

780
781
782
783
784
785
786
787
788
789
790
791
792
    /*
     * starting to find if it is MEM/MEM64/IO
     * using libdevinfo
     */
    if ((rnode = di_init(nexus->dev_path, DINFOCPYALL)) == DI_NODE_NIL) {
	err = errno;
	(void) fprintf(stderr, "di_init failed: %s\n", strerror(errno));
    } else {
	args.bus = dev->bus;
	args.dev = dev->dev;
	args.func = dev->func;
	(void) di_walk_node(rnode, DI_WALK_CLDFIRST,
		(void *)&args, find_target_node);
793
    }
794

795
    if (args.node != DI_NODE_NIL) {
796
797
798
799
800
801
802
803
804
805
806
#ifdef __sparc
	di_minor_t minor;
#endif

#ifdef __sparc
	if (minor = di_minor_next(args.node, DI_MINOR_NIL))
	    MAPPING_DEV_PATH(dev) = di_devfs_minor_path (minor);
	else
	    MAPPING_DEV_PATH(dev) = NULL;
#endif

807
	/*
Alan Coopersmith's avatar
Alan Coopersmith committed
808
	 * It will succeed for sure, because it was
809
810
811
812
813
	 * successfully called in find_target_node
	 */
	len = di_prop_lookup_ints(DDI_DEV_T_ANY, args.node,
				  "assigned-addresses",
				  &regbuf);
814

815
816
817
818
819
820
#ifdef __sparc
	if ((len <= 0) && di_phdl) {
	    len = di_prom_prop_lookup_ints(di_phdl, args.node,
				"assigned-addresses", &regbuf);
	}
#endif
821
822
823
    }

    if (len <= 0)
824
	goto cleanup;
825
826


827
828
829
830
831
832
833
834
835
836
837
    /*
     * how to find the size of rom???
     * if the device has expansion rom,
     * it must be listed in the last
     * cells because solaris find probe
     * the base address from offset 0x10
     * to 0x30h. So only check the last
     * item.
     */
    reg = (pci_regspec_t *)&regbuf[len - CELL_NUMS_1275];
    if (PCI_REG_REG_G(reg->pci_phys_hi) == PCI_CONF_ROM) {
838
	/*
839
	 * rom can only be 32 bits
840
	 */
841
842
843
844
845
846
847
848
849
850
851
852
	dev->rom_size = reg->pci_size_low;
	len = len - CELL_NUMS_1275;
    }
    else {
	/*
	 * size default to 64K and base address
	 * default to 0xC0000
	 */
	dev->rom_size = 0x10000;
    }

    /*
853
854
     * Solaris has its own BAR index.
     * Linux give two region slot for 64 bit address.
855
856
857
858
     */
    for (i = 0; i < len; i = i + CELL_NUMS_1275) {

	reg = (pci_regspec_t *)&regbuf[i];
859
860
861
862
863
864
865
866
867
	ent = reg->pci_phys_hi & 0xff;
	/*
	 * G35 broken in BAR0
	 */
	ent = (ent - PCI_CONF_BASE0) >> 2;
	if (ent >= 6) {
	    fprintf(stderr, "error ent = %d\n", ent);
	    break;
	}
868
869
870
871
872
873
874
875
876
877
878

	/*
	 * non relocatable resource is excluded
	 * such like 0xa0000, 0x3b0. If it is met,
	 * the loop is broken;
	 */
	if (!PCI_REG_REG_G(reg->pci_phys_hi))
	    break;

	if (reg->pci_phys_hi & PCI_PREFETCH_B) {
	    dev->regions[ent].is_prefetchable = 1;
879
	}
880

881
882
883
884
885
886
887
888
889
890

	/*
	 * We split the shift count 32 into two 16 to
	 * avoid the complaining of the compiler
	 */
	dev->regions[ent].base_addr = reg->pci_phys_low +
	    ((reg->pci_phys_mid << 16) << 16);
	dev->regions[ent].size = reg->pci_size_low +
	    ((reg->pci_size_hi << 16) << 16);

891
892
893
894
895
896
897
898
	switch (reg->pci_phys_hi & PCI_REG_ADDR_M) {
	    case PCI_ADDR_IO:
		dev->regions[ent].is_IO = 1;
		break;
	    case PCI_ADDR_MEM32:
		break;
	    case PCI_ADDR_MEM64:
		dev->regions[ent].is_64 = 1;
899
900
901
		/*
		 * Skip one slot for 64 bit address
		 */
902
		break;
903
	}
904
    }
905

906
907
908
909
  cleanup:
    if (rnode != DI_NODE_NIL) {
	di_fini(rnode);
    }
910
911
912
    return (err);
}

913
/**
914
 * Map a memory region for a device using /dev/xsvc (x86) or fb device (sparc)
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
 *
 * \param dev   Device whose memory region is to be mapped.
 * \param map   Parameters of the mapping that is to be created.
 *
 * \return
 * Zero on success or an \c errno value on failure.
 */
static int
pci_device_solx_devfs_map_range(struct pci_device *dev,
				struct pci_device_mapping *map)
{
    const int prot = ((map->flags & PCI_DEV_MAP_FLAG_WRITABLE) != 0)
			? (PROT_READ | PROT_WRITE) : PROT_READ;
    int err = 0;

930
    const char *map_dev;
931
932
    int		map_fd;

933
934
#ifdef __sparc
    char	map_dev_buf[128];
935

936
937
938
939
    if (MAPPING_DEV_PATH(dev)) {
	snprintf(map_dev_buf, sizeof (map_dev_buf), "%s%s",
		 "/devices", MAPPING_DEV_PATH(dev));
	map_dev = map_dev_buf;
940
    }
941
942
    else
	map_dev = "/dev/fb0";
943

944
    map_fd = -1;
945
946
#else
    /*
947
948
     * Still uses xsvc to do the user space mapping on x86/x64,
     * caches open fd across multiple calls.
949
     */
950
951
952
953
954
955
    map_dev = "/dev/xsvc";
    map_fd = xsvc_fd;
#endif

    if (map_fd < 0) {
	if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) {
956
	    err = errno;
957
	    (void) fprintf(stderr, "can not open %s: %s\n", map_dev,
958
959
960
961
962
			   strerror(errno));
	    return err;
	}
    }

963
    map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    if (map->memory == MAP_FAILED) {
	err = errno;

	(void) fprintf(stderr, "map rom region =%llx failed: %s\n",
		       map->base, strerror(errno));
    }

#ifdef __sparc
    close (map_fd);
#endif

    return err;
}

978
/*
Alan Coopersmith's avatar
Alan Coopersmith committed
979
 * Solaris version: read the VGA ROM data
980
981
982
983
 */
static int
pci_device_solx_devfs_read_rom( struct pci_device * dev, void * buffer )
{
Alan Coopersmith's avatar
Alan Coopersmith committed
984
985
986
987
988
989
    int err;
    struct pci_device_mapping prom = {
	.base = 0xC0000,
	.size = dev->rom_size,
	.flags = 0
    };
990

Alan Coopersmith's avatar
Alan Coopersmith committed
991
992
993
994
995
996
    err = pci_device_solx_devfs_map_range(dev, &prom);
    if (err == 0) {
	(void) bcopy(prom.memory, buffer, dev->rom_size);

	if (munmap(prom.memory, dev->rom_size) == -1) {
	    err = errno;
997
	}
998
    }
Alan Coopersmith's avatar
Alan Coopersmith committed
999
    return err;
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
}

/*
 * solaris version: Read the configurations space of the devices
 */
static int
pci_device_solx_devfs_read( struct pci_device * dev, void * data,
			     pciaddr_t offset, pciaddr_t size,
			     pciaddr_t * bytes_read )
{
1010
1011
1012
    pcitool_reg_t cfg_prg;
    int err = 0;
    int i = 0;
1013
1014
1015
1016
1017
1018
1019
    nexus_t *nexus;

#ifdef __sparc
    nexus = find_nexus_for_dev(dev);
#else
    nexus = find_nexus_for_bus(dev->domain, dev->bus);
#endif
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039

    *bytes_read = 0;

    if ( nexus == NULL ) {
	return ENODEV;
    }

    cfg_prg.offset = offset;
    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
    cfg_prg.bus_no = dev->bus;
    cfg_prg.dev_no = dev->dev;
    cfg_prg.func_no = dev->func;
    cfg_prg.barnum = 0;
    cfg_prg.user_version = PCITOOL_USER_VERSION;

    for (i = 0; i < size; i += PCITOOL_ACC_ATTR_SIZE(PCITOOL_ACC_ATTR_SIZE_1))
    {
	cfg_prg.offset = offset + i;

	if ((err = ioctl(nexus->fd, PCITOOL_DEVICE_GET_REG, &cfg_prg)) != 0) {
1040
1041
	    fprintf(stderr, "read bdf<%s,%x,%x,%x,%llx> config space failure\n",
		    nexus->path,
1042
1043
1044
1045
1046
1047
		    cfg_prg.bus_no,
		    cfg_prg.dev_no,
		    cfg_prg.func_no,
		    cfg_prg.offset);
	    fprintf(stderr, "Failure cause = %x\n", err);
	    break;
1048
	}
1049

1050
1051
1052
1053
1054
1055
	((uint8_t *)data)[i] = (uint8_t)cfg_prg.data;
	/*
	 * DWORDS Offset or bytes Offset ??
	 */
    }
    *bytes_read = i;
1056

1057
    return (err);
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
}

/*
 * Solaris version
 */
static int
pci_device_solx_devfs_write( struct pci_device * dev, const void * data,
			     pciaddr_t offset, pciaddr_t size,
			     pciaddr_t * bytes_written )
{
1068
1069
1070
    pcitool_reg_t cfg_prg;
    int err = 0;
    int cmd;
1071
1072
1073
1074
1075
1076
1077
    nexus_t *nexus;

#ifdef __sparc
    nexus = find_nexus_for_dev(dev);
#else
    nexus = find_nexus_for_bus(dev->domain, dev->bus);
#endif
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

    if ( bytes_written != NULL ) {
	*bytes_written = 0;
    }

    if ( nexus == NULL ) {
	return ENODEV;
    }

    cfg_prg.offset = offset;
    switch (size) {
        case 1:
	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_1 + NATIVE_ENDIAN;
1091
	    cfg_prg.data = *((const uint8_t *)data);
1092
1093
1094
	    break;
        case 2:
	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_2 + NATIVE_ENDIAN;
1095
	    cfg_prg.data = *((const uint16_t *)data);
1096
1097
1098
	    break;
        case 4:
	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_4 + NATIVE_ENDIAN;
1099
	    cfg_prg.data = *((const uint32_t *)data);
1100
1101
1102
	    break;
        case 8:
	    cfg_prg.acc_attr = PCITOOL_ACC_ATTR_SIZE_8 + NATIVE_ENDIAN;
1103
	    cfg_prg.data = *((const uint64_t *)data);
1104
1105
	    break;
        default:
Alan Coopersmith's avatar
Alan Coopersmith committed
1106
	    return EINVAL;
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
    }
    cfg_prg.bus_no = dev->bus;
    cfg_prg.dev_no = dev->dev;
    cfg_prg.func_no = dev->func;
    cfg_prg.barnum = 0;
    cfg_prg.user_version = PCITOOL_USER_VERSION;

    /*
     * Check if this device is bridge device.
     * If it is, it is also a nexus node???
     * It seems that there is no explicit
     * PCI nexus device for X86, so not applicable
     * from pcitool_bus_reg_ops in pci_tools.c
     */
    cmd = PCITOOL_DEVICE_SET_REG;

    if ((err = ioctl(nexus->fd, cmd, &cfg_prg)) != 0) {
1124
	return (err);
1125
1126
1127
1128
    }
    *bytes_written = size;

    return (err);
1129
1130
}

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
static struct pci_io_handle *
pci_device_solx_devfs_open_legacy_io(struct pci_io_handle *ret,
				     struct pci_device *dev,
				     pciaddr_t base, pciaddr_t size)
{
#ifdef __x86
    if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) == 0) {
	ret->base = base;
	ret->size = size;
	return ret;
    }
#endif
    return NULL;
}

static uint32_t
pci_device_solx_devfs_read32(struct pci_io_handle *handle, uint32_t reg)
{
#ifdef __x86
    uint16_t port = (uint16_t) (handle->base + reg);
    uint32_t ret;
    __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port));
    return ret;
#else
    return *(uint32_t *)((uintptr_t)handle->memory + reg);
#endif
}
1158

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
static uint16_t
pci_device_solx_devfs_read16(struct pci_io_handle *handle, uint32_t reg)
{
#ifdef __x86
    uint16_t port = (uint16_t) (handle->base + reg);
    uint16_t ret;
    __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port));
    return ret;
#else
    return *(uint16_t *)((uintptr_t)handle->memory + reg);
#endif
}

static uint8_t
pci_device_solx_devfs_read8(struct pci_io_handle *handle, uint32_t reg)
{
#ifdef __x86
    uint16_t port = (uint16_t) (handle->base + reg);
    uint8_t ret;
    __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port));
    return ret;
#else
    return *(uint8_t *)((uintptr_t)handle->memory + reg);
#endif
}

static void
pci_device_solx_devfs_write32(struct pci_io_handle *handle, uint32_t reg,
    uint32_t data)
{
#ifdef __x86
      uint16_t port = (uint16_t) (handle->base + reg);
      __asm__ __volatile__("outl %0,%1"::"a"(data), "d"(port));
#else
      *(uint16_t *)((uintptr_t)handle->memory + reg) = data;
#endif
}

static void
pci_device_solx_devfs_write16(struct pci_io_handle *handle, uint32_t reg,
    uint16_t data)
{
#ifdef __x86
      uint16_t port = (uint16_t) (handle->base + reg);
      __asm__ __volatile__("outw %0,%1"::"a"(data), "d"(port));
#else
    *(uint8_t *)((uintptr_t)handle->memory + reg) = data;
#endif
}

static void
pci_device_solx_devfs_write8(struct pci_io_handle *handle, uint32_t reg,
    uint8_t data)
{
#ifdef __x86
      uint16_t port = (uint16_t) (handle->base + reg);
      __asm__ __volatile__("outb %0,%1"::"a"(data), "d"(port));
#else
      *(uint32_t *)((uintptr_t)handle->memory + reg) = data;
#endif
}

static int
pci_device_solx_devfs_map_legacy(struct pci_device *dev, pciaddr_t base,
				 pciaddr_t size, unsigned map_flags,
				 void **addr)
{
    int err;
    struct pci_device_mapping map = {
	.base = base,
	.size = size,
	.flags = map_flags,
    };

    err = pci_device_solx_devfs_map_range(dev, &map);
    if (err == 0)
	*addr = map.memory;
    return err;
}

static int
pci_device_solx_devfs_unmap_legacy(struct pci_device *dev,
				   void *addr, pciaddr_t size)
{
    struct pci_device_mapping map = {
	.memory = addr,
	.size = size,
    };

    return pci_device_generic_unmap_range(dev, &map);
}
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261

static const struct pci_system_methods solx_devfs_methods = {
    .destroy = pci_system_solx_devfs_destroy,
    .destroy_device = NULL,
    .read_rom = pci_device_solx_devfs_read_rom,
    .probe = pci_device_solx_devfs_probe,
    .map_range = pci_device_solx_devfs_map_range,
    .unmap_range = pci_device_generic_unmap_range,

    .read = pci_device_solx_devfs_read,
    .write = pci_device_solx_devfs_write,

1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
    .fill_capabilities = pci_fill_capabilities_generic,

    .open_legacy_io = pci_device_solx_devfs_open_legacy_io,
    .read32 = pci_device_solx_devfs_read32,
    .read16 = pci_device_solx_devfs_read16,
    .read8 = pci_device_solx_devfs_read8,
    .write32 = pci_device_solx_devfs_write32,
    .write16 = pci_device_solx_devfs_write16,
    .write8 = pci_device_solx_devfs_write8,
    .map_legacy = pci_device_solx_devfs_map_legacy,
    .unmap_legacy = pci_device_solx_devfs_unmap_legacy,
1273
1274
1275
1276
1277
};

/*
 * Attempt to access PCI subsystem using Solaris's devfs interface.
 * Solaris version
1278
 */
1279
1280
_pci_hidden int
pci_system_solx_devfs_create( void )
1281
{
1282
    int err = 0;
1283
1284
1285
    di_node_t di_node;
    probe_info_t pinfo;
    struct pci_device_private *devices;
1286

1287
1288
1289
    if (nexus_list != NULL) {
	return 0;
    }
1290

1291
    if ((di_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
1292
	err = errno;
1293
1294
1295
	(void) fprintf(stderr, "di_init() failed: %s\n",
		       strerror(errno));
	return (err);
1296
1297
    }

1298
1299
1300
1301
1302
    if ((devices = calloc(INITIAL_NUM_DEVICES,
			sizeof (struct pci_device_private))) == NULL) {
	err = errno;
	di_fini(di_node);
	return (err);
1303
    }
1304

1305
1306
1307
#ifdef __sparc
    if ((di_phdl = di_prom_init()) == DI_PROM_HANDLE_NIL)
	(void) fprintf(stderr, "di_prom_init failed: %s\n", strerror(errno));
1308
1309
#endif

1310
1311
1312
1313
    pinfo.num_allocated_elems = INITIAL_NUM_DEVICES;
    pinfo.num_devices = 0;
    pinfo.devices = devices;
    (void) di_walk_minor(di_node, DDI_NT_REGACC, 0, &pinfo, probe_nexus_node);
1314

1315
1316
1317
1318
1319
1320
    di_fini(di_node);

    if ((pci_sys = calloc(1, sizeof (struct pci_system))) == NULL) {
	err = errno;
	free(devices);
	return (err);
1321
    }
1322

1323
1324
1325
    pci_sys->methods = &solx_devfs_methods;
    pci_sys->devices = pinfo.devices;
    pci_sys->num_devices = pinfo.num_devices;
1326

1327
    return (err);
1328
}