Пример #1
0
static int
atkbdc_attach(device_t dev)
{
	atkbdc_softc_t	*sc;
	struct resource *port;
	int		unit;
	int		error;
	int		rid;
	int		i;

	unit = device_get_unit(dev);
	sc = *(atkbdc_softc_t **)device_get_softc(dev);
	if (sc == NULL) {
		/*
		 * We have to maintain two copies of the kbdc_softc struct,
		 * as the low-level console needs to have access to the
		 * keyboard controller before kbdc is probed and attached. 
		 * kbdc_soft[] contains the default entry for that purpose.
		 * See atkbdc.c. XXX
		 */
		sc = atkbdc_get_softc(unit);
		if (sc == NULL)
			return ENOMEM;
	}

	/* XXX should track resource in softc */
	rid = 0;
	port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
				  0, ~0, IO_KBDSIZE, RF_ACTIVE);
	if (!port)
		return ENXIO;
	error = atkbdc_attach_unit(unit, sc, rman_get_start(port));
	if (error)
		return error;
	*(atkbdc_softc_t **)device_get_softc(dev) = sc;

	/*
	 * Add all devices configured to be attached to atkbdc0.
	 */
	for (i = resource_query_string(-1, "at", "atkbdc0");
	     i != -1;
	     i = resource_query_string(i, "at", "atkbdc0")) {
		atkbdc_add_device(dev, resource_query_name(i),
				  resource_query_unit(i));
	}

	/*
	 * and atkbdc?
	 */
	for (i = resource_query_string(-1, "at", "atkbdc");
	     i != -1;
	     i = resource_query_string(i, "at", "atkbdc")) {
		atkbdc_add_device(dev, resource_query_name(i),
				  resource_query_unit(i));
	}

	bus_generic_attach(dev);

	return 0;
}
Пример #2
0
static int
isahint_identify(driver_t *driver, device_t parent)
{
	int i;
	static char buf[] = "isaXXX";

	/*
	 * If the parent bus is already attached we are being called to
	 * rescan.  We do not suppot rescanning the hints, just return
	 * success.
	 */
	if (device_get_state(parent) == DS_ATTACHED)
		return(0);
	if (device_get_state(parent) == DS_INPROGRESS)
		return(0);

	/*
	 * Add all devices configured to be attached to parent.
	 */
	ksprintf(buf, "isa%d", device_get_unit(parent));
	for (i = resource_query_string(-1, "at", buf);
	     i != -1;
	     i = resource_query_string(i, "at", buf)) {
		if (strcmp(resource_query_name(i), "atkbd") == 0)
			continue;	/* old GENERIC kludge */
		isahint_add_device(parent,
				   resource_query_name(i),
				   resource_query_unit(i));
	}

	/*
	 * and isa?
	 */
	for (i = resource_query_string(-1, "at", "isa");
	     i != -1;
	     i = resource_query_string(i, "at", "isa")) {
		if (strcmp(resource_query_name(i), "atkbd") == 0)
			continue;	/* old GENERIC kludge */
		isahint_add_device(parent,
				   resource_query_name(i),
				   resource_query_unit(i));
	}
	return(0);
}
Пример #3
0
static int
atkbdc_attach(device_t dev)
{
	atkbdc_softc_t	*sc;
	int		unit;
	int		error;
	int		rid;
	int		i;

	lwkt_gettoken(&tty_token);
	unit = device_get_unit(dev);
	sc = *(atkbdc_softc_t **)device_get_softc(dev);
	if (sc == NULL) {
		/*
		 * We have to maintain two copies of the kbdc_softc struct,
		 * as the low-level console needs to have access to the
		 * keyboard controller before kbdc is probed and attached. 
		 * kbdc_soft[] contains the default entry for that purpose.
		 * See atkbdc.c. XXX
		 */
		sc = atkbdc_get_softc(unit);
		if (sc == NULL) {
			lwkt_reltoken(&tty_token);
			return ENOMEM;
		}
	}

	rid = 0;
	sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
				       RF_ACTIVE);
	if (sc->port0 == NULL) {
		lwkt_reltoken(&tty_token);
		return ENXIO;
	}
	rid = 1;
	sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
				       RF_ACTIVE);
	if (sc->port1 == NULL) {
		bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
		lwkt_reltoken(&tty_token);
		return ENXIO;
	}

	error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
	if (error) {
		bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
		bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
		lwkt_reltoken(&tty_token);
		return error;
	}
	*(atkbdc_softc_t **)device_get_softc(dev) = sc;

	/*
	 * Add all devices configured to be attached to atkbdc0.
	 */
	for (i = resource_query_string(-1, "at", device_get_nameunit(dev));
	     i != -1;
	     i = resource_query_string(i, "at", device_get_nameunit(dev))) {
		atkbdc_add_device(dev, resource_query_name(i),
				  resource_query_unit(i));
	}

	/*
	 * and atkbdc?
	 */
	for (i = resource_query_string(-1, "at", device_get_name(dev));
	     i != -1;
	     i = resource_query_string(i, "at", device_get_name(dev))) {
		atkbdc_add_device(dev, resource_query_name(i),
				  resource_query_unit(i));
	}

	bus_generic_attach(dev);

	lwkt_reltoken(&tty_token);
	return 0;
}