Ejemplo n.º 1
0
/* Add a dummy device to reserve I/O space for hotpluggable devices.  */
void intel_acpi_pcie_hotplug_scan_slot(struct bus *bus)
{
	struct device *slot;
	struct device_path slot_path = { .type = DEVICE_PATH_NONE };
	slot = alloc_dev(bus, &slot_path);
	slot->ops = &slot_dev_ops;
}
Ejemplo n.º 2
0
/*
 * add the given driver/unit reference to the `rawdev' structure identified
 * by `cookie'
 * If a new `driver' structure needs to be created, associate the given
 * choosing function and driver private data with it.
 */
void
preen_addunit(
	void    *cookie,
	char	*dname,		/* driver name */
	int	(*cf)(),	/* candidate choosing function */
	void	*datap,		/* driver private data */
	uint_t	unit)		/* unit number */
{
	int drvid;
	struct driver *dp;
	struct onedev *devp;
	struct rawdev *rdp = (struct rawdev *)cookie;

	/*
	 * locate the driver struct
	 */
	dp = NULL;
	for (drvid = 0; drvid < ndrivers; drvid++) {
		if (strcmp(dlist[drvid].name, dname) == 0) {
			dp = &dlist[drvid];
			break;
		}
	}

	if (dp == NULL) {
		/*
		 * driver struct doesn't exist yet -- create one
		 */
		if (cf == NULL)
			cf = chooseone;
		drvid = alloc_driver(dname, cf, datap);
		dp = &dlist[drvid];
	}

	for (devp = rdp->alldevs; devp != NULL; devp = devp->nxtdev) {
		/*
		 * see if this device already references the given driver
		 */
		if (devp->drvid == drvid)
			break;
	}

	if (devp == NULL) {
		/*
		 * allocate a new `struct onedev' and chain it in
		 * rdp->alldevs...
		 */
		devp = alloc_dev(drvid);
		devp->nxtdev = rdp->alldevs;
		rdp->alldevs = devp;
	}

	/*
	 * add `unit' to the unitmap in devp
	 */
	addunit(devp, unit);
}
Ejemplo n.º 3
0
/*
 * Constructor for a new device.
 */
int dm_create(int minor, struct mapped_device **result)
{
	struct mapped_device *md;

	md = alloc_dev(minor);
	if (!md)
		return -ENXIO;

	*result = md;
	return 0;
}
Ejemplo n.º 4
0
Archivo: dm.c Proyecto: wxlong/Test
/*
 * Constructor for a new device.
 */
static int create_aux(unsigned int minor, int persistent,
		      struct mapped_device **result)
{
	struct mapped_device *md;

	md = alloc_dev(minor, persistent);
	if (!md)
		return -ENXIO;

	*result = md;
	return 0;
}
Ejemplo n.º 5
0
forensic1394_result platform_update_device_list(forensic1394_bus *bus)
{
    int i;
    int perm_skipped = 0;
    forensic1394_result ret = FORENSIC1394_RESULT_SUCCESS;

    glob_t globdev;

    // Glob the available firewire devices attached to the system
    glob("/dev/fw*", 0, NULL, &globdev);

    for (i = 0; i < globdev.gl_pathc; i++)
    {
        const char *devpath = globdev.gl_pathv[i];
        uint32_t rom[FORENSIC1394_CSR_SZ];

        struct fw_cdev_event_bus_reset reset;

        // Fill out a get info request
        struct fw_cdev_get_info get_info = {
            .version    = FW_CDEV_VERSION,
            .rom        = PTR_TO_U64(rom),
            .rom_length = sizeof(rom),
            .bus_reset  = PTR_TO_U64(&reset)
        };

        // Open up the device
        int fd = open(devpath, O_RDWR);

        // Ensure the device was opened
        if (fd == -1)
        {
            // See if the failure was due to a permissions problem
            if (errno == EACCES)
            {
                perm_skipped++;
            }

            // Not fatal; continue
            continue;
        }

        // Send the get info request
        if (ioctl(fd, FW_CDEV_IOC_GET_INFO, &get_info) == -1)
        {
            // Highly unlikely; probably fatal
            ret = FORENSIC1394_RESULT_OTHER_ERROR;
            perm_skipped = -1;
            break;
        }

        // See if the node is foreign (we only want attached devices)
        if (reset.node_id != reset.local_node_id)
        {
            // Allocate a new device
            forensic1394_dev *currdev = alloc_dev(devpath,
                                                  &get_info,
                                                  &reset);

            // Save a reference to the bus
            currdev->bus = bus;

            // Add this new device to the device list
            currdev->next = bus->dev_link;
            bus->dev_link = currdev;
            bus->ndev++;
        }

        // Close the device (it may be opened up later)
        close(fd);
    }

    globfree(&globdev);

    // If we found no devices but were forced to skip some due to permission-
    // related errors then return FORENSIC1394_RESULT_NO_PERM.
    if (bus->ndev == 0 && perm_skipped > 0)
    {
        ret = FORENSIC1394_RESULT_NO_PERM;
    }

    return ret;
}