Ejemplo n.º 1
0
void
fdcattach(struct device *parent, struct device *self, void *aux)
{
	struct fdc_softc *fdc = (void *)self;
	bus_space_tag_t iot;
	bus_space_handle_t ioh;
	bus_space_handle_t ioh_ctl;
	struct isa_attach_args *ia = aux;
	struct fdc_attach_args fa;
	int type;

	iot = ia->ia_iot;

	/* Re-map the I/O space. */
	if (bus_space_map(iot, ia->ia_iobase, FDC_NPORT, 0, &ioh) ||
	    bus_space_map(iot, ia->ia_iobase + FDCTL_OFFSET,
			  FDCTL_NPORT, 0, &ioh_ctl))
		panic("fdcattach: couldn't map I/O ports");

	fdc->sc_iot = iot;
	fdc->sc_ioh = ioh;
	fdc->sc_ioh_ctl = ioh_ctl;

	fdc->sc_drq = ia->ia_drq;
	fdc->sc_state = DEVIDLE;
	TAILQ_INIT(&fdc->sc_link.fdlink.sc_drives);	/* XXX */

	printf("\n");

	fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
	    IPL_BIO, fdcintr, fdc, fdc->sc_dev.dv_xname);

#if defined(__i386__) || defined(__amd64__)
	/*
	 * The NVRAM info only tells us about the first two disks on the
	 * `primary' floppy controller.
	 */
	if (fdc->sc_dev.dv_unit == 0)
		type = mc146818_read(NULL, NVRAM_DISKETTE); /* XXX softc */
	else
#endif
		type = -1;

	timeout_set(&fdc->fdcpseudointr_to, fdcpseudointr, fdc);

	/* physical limit: four drives per controller. */
	for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
		fa.fa_flags = 0;
		fa.fa_type = 0;
#if NFD > 0
		if (type >= 0 && fa.fa_drive < 2)
			fa.fa_deftype = fd_nvtotype(fdc->sc_dev.dv_xname,
			    type, fa.fa_drive);
		else
#endif
			fa.fa_deftype = NULL;		/* unknown */
		(void)config_found(self, (void *)&fa, fddprint);
	}
}
Ejemplo n.º 2
0
void
fdcfinishattach(device_t self)
{
	struct fdc_softc *fdc = device_private(self);
	bus_space_tag_t iot = fdc->sc_iot;
	bus_space_handle_t ioh = fdc->sc_ioh;
	struct fdc_attach_args fa;

	/*
	 * Reset the controller to get it into a known state. Not all
	 * probes necessarily need do this to discover the controller up
	 * front, so don't assume anything.
	 */

	bus_space_write_1(iot, ioh, fdout, 0);
	delay(100);
	bus_space_write_1(iot, ioh, fdout, FDO_FRST);

	/* see if it can handle a command */
	if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0) {
		aprint_normal_dev(fdc->sc_dev, "can't reset controller\n");
		return;
	}
	out_fdc(iot, ioh, 0xdf);
	out_fdc(iot, ioh, 2);

#if defined(i386) || defined(x86_64)
	/*
	 * The NVRAM info only tells us about the first two disks on the
	 * `primary' floppy controller.
	 */
	/* XXX device_unit() abuse */
	if (device_unit(fdc->sc_dev) == 0) {
		int type = mc146818_read(NULL, NVRAM_DISKETTE); /* XXX softc */
		fdc->sc_known = 1;
		fdc->sc_knownfds[0] = fd_nvtotype(device_xname(fdc->sc_dev),
		    type, 0);
		if (fdc->sc_knownfds[0] != NULL)
			fdc->sc_present |= 1;
		fdc->sc_knownfds[1] = fd_nvtotype(device_xname(fdc->sc_dev),
		    type, 1);
		if (fdc->sc_knownfds[1] != NULL)
			fdc->sc_present |= 2;
	}
#endif /* i386 || x86_64 */

	/* physical limit: four drives per controller. */
	fdc->sc_state = PROBING;
	for (fa.fa_drive = 0; fa.fa_drive < 4; fa.fa_drive++) {
		if (fdc->sc_known) {
			if (fdc->sc_present & (1 << fa.fa_drive)) {
				fa.fa_deftype = fdc->sc_knownfds[fa.fa_drive];
				config_found(fdc->sc_dev, (void *)&fa,
				    fdprint);
			}
		} else {
#if defined(atari)
			/*
			 * Atari has a different ordening, defaults to 1.44
			 */
			fa.fa_deftype = &fd_types[2];
#else
			/*
			 * Default to 1.44MB on Alpha and BeBox.  How do we tell
			 * on these platforms?
			 */
			fa.fa_deftype = &fd_types[0];
#endif
			(void)config_found_ia(fdc->sc_dev, "fdc", (void *)&fa, fdprint);
		}
	}
	fdc->sc_state = DEVIDLE;
}