⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pciide.c

📁 国产CPU-龙芯(loongson)BIOS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifdef __OpenBSD__struct        cfdriver pciide_cd = {      NULL, "pciide", DV_DULL};#endifint	pciide_chipen __P((struct pciide_softc *, struct pci_attach_args *));int	pciide_mapregs_compat __P(( struct pci_attach_args *,	    struct pciide_channel *, int, bus_size_t *, bus_size_t*));int	pciide_mapregs_native __P((struct pci_attach_args *, 	    struct pciide_channel *, bus_size_t *, bus_size_t *,	    int (*pci_intr) __P((void *))));void	pciide_mapreg_dma __P((struct pciide_softc *,	    struct pci_attach_args *));int	pciide_chansetup __P((struct pciide_softc *, int, pcireg_t));void	pciide_mapchan __P((struct pci_attach_args *,	    struct pciide_channel *, pcireg_t, bus_size_t *, bus_size_t *,	    int (*pci_intr) __P((void *))));int	pciiide_chan_candisable __P((struct pciide_channel *));void	pciide_map_compat_intr __P(( struct pci_attach_args *,	    struct pciide_channel *, int, int));int	pciide_print __P((void *, const char *pnp));int	pciide_compat_intr __P((void *));int	pciide_pci_intr __P((void *));const struct pciide_product_desc* pciide_lookup_product __P((u_int32_t));const struct pciide_product_desc *pciide_lookup_product(id)	u_int32_t id;{	const struct pciide_product_desc *pp;	const struct pciide_vendor_desc *vp;	int i;	for (i = 0, vp = pciide_vendors;	    i < sizeof(pciide_vendors)/sizeof(pciide_vendors[0]);	    vp++, i++)		if (PCI_VENDOR(id) == vp->ide_vendor)			break;	if (i == sizeof(pciide_vendors)/sizeof(pciide_vendors[0]))		return NULL;	for (pp = vp->ide_products, i = 0; i < vp->ide_nproducts; pp++, i++)		if (PCI_PRODUCT(id) == pp->ide_product)			break;	if (i == vp->ide_nproducts)		return NULL;	return pp;}intpciide_match(parent, match, aux)	struct device *parent;#ifdef __OpenBSD__	void *match;#else	struct cfdata *match;#endif	void *aux;{	struct pci_attach_args *pa = aux;	const struct pciide_product_desc *pp;	/*	 * Check the ID register to see that it's a PCI IDE controller.	 * If it is, we assume that we can deal with it; it _should_	 * work in a standardized way...	 */	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_IDE) {		return (1);	}	/* 	 * Some controllers (e.g. promise Ultra-33) don't claim to be PCI IDE	 * controllers. Let see if we can deal with it anyway.	 */	pp = pciide_lookup_product(pa->pa_id);	if (pp  && (pp->ide_flags & IDE_PCI_CLASS_OVERRIDE)) {		return (1);	}	return (0);}voidpciide_attach(parent, self, aux)	struct device *parent, *self;	void *aux;{	struct pci_attach_args *pa = aux;#ifndef PMON	pci_chipset_tag_t pc = pa->pa_pc;#endif	pcitag_t tag = pa->pa_tag;	struct pciide_softc *sc = (struct pciide_softc *)self;	pcireg_t csr;	char devinfo[256];	sc->sc_pp = pciide_lookup_product(pa->pa_id);	if (sc->sc_pp == NULL) {		sc->sc_pp = &default_product_desc;		pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);	}	sc->sc_pc = pa->pa_pc;	sc->sc_tag = pa->pa_tag;#ifdef WDCDEBUG       if (wdcdebug_pciide_mask & DEBUG_PROBE)               printf("sc_pc %x, sc_tag %x\n", sc->sc_pc, sc->sc_tag);#endif	sc->sc_pp->chip_map(sc, pa);	if (sc->sc_dma_ok) {		csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);		csr |= PCI_COMMAND_MASTER_ENABLE;		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);	}	WDCDEBUG_PRINT(("pciide: command/status register=%x\n",	    pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG)), DEBUG_PROBE);}/* tell wether the chip is enabled or not */intpciide_chipen(sc, pa)	struct pciide_softc *sc;	struct pci_attach_args *pa;{	pcireg_t csr;	if ((pa->pa_flags & PCI_FLAGS_IO_ENABLED) == 0) {		csr = pci_conf_read(sc->sc_pc, sc->sc_tag,		PCI_COMMAND_STATUS_REG);	printf(": device disabled (at %s)\n",		(csr & PCI_COMMAND_IO_ENABLE) == 0 ?		"device" : "bridge");		return 0;	}	return 1;}intpciide_mapregs_compat(pa, cp, compatchan, cmdsizep, ctlsizep)	struct pci_attach_args *pa;	struct pciide_channel *cp;	int compatchan;	bus_size_t *cmdsizep, *ctlsizep;{	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;	struct channel_softc *wdc_cp = &cp->wdc_channel;	cp->compat = 1;	*cmdsizep = PCIIDE_COMPAT_CMD_SIZE;	*ctlsizep = PCIIDE_COMPAT_CTL_SIZE;	wdc_cp->cmd_iot = pa->pa_iot;	if (bus_space_map(wdc_cp->cmd_iot, PCIIDE_COMPAT_CMD_BASE(compatchan),	    PCIIDE_COMPAT_CMD_SIZE, 0, &wdc_cp->cmd_ioh) != 0) {		printf("%s: couldn't map %s cmd regs\n",		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);		return (0);	}	wdc_cp->ctl_iot = pa->pa_iot;	if (bus_space_map(wdc_cp->ctl_iot, PCIIDE_COMPAT_CTL_BASE(compatchan),	    PCIIDE_COMPAT_CTL_SIZE, 0, &wdc_cp->ctl_ioh) != 0) {		printf("%s: couldn't map %s ctl regs\n",		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);		bus_space_unmap(wdc_cp->cmd_iot, wdc_cp->cmd_ioh,		    PCIIDE_COMPAT_CMD_SIZE);		return (0);	}	return (1);}intpciide_mapregs_native(pa, cp, cmdsizep, ctlsizep, pci_intr)	struct pci_attach_args * pa;	struct pciide_channel *cp;	bus_size_t *cmdsizep, *ctlsizep;	int (*pci_intr) __P((void *));{	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;	struct channel_softc *wdc_cp = &cp->wdc_channel;	const char *intrstr;	pci_intr_handle_t intrhandle;	cp->compat = 0;	if (sc->sc_pci_ih == NULL) {		if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,		    pa->pa_intrline, &intrhandle) != 0) {			printf("%s: couldn't map native-PCI interrupt\n",			    sc->sc_wdcdev.sc_dev.dv_xname);			return 0;		}			intrstr = pci_intr_string(pa->pa_pc, intrhandle);#ifdef __OpenBSD__		sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,		    intrhandle, IPL_BIO, pci_intr, sc,		    sc->sc_wdcdev.sc_dev.dv_xname);#else		sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,		    intrhandle, IPL_BIO, pci_intr, sc);#endif		if (sc->sc_pci_ih != NULL) {			printf("%s: using %s for native-PCI interrupt\n",			    sc->sc_wdcdev.sc_dev.dv_xname,			    intrstr ? intrstr : "unknown interrupt");		} else {			printf("%s: couldn't establish native-PCI interrupt",			    sc->sc_wdcdev.sc_dev.dv_xname);			if (intrstr != NULL)				printf(" at %s", intrstr);			printf("\n");			return 0;		}	}	cp->ih = sc->sc_pci_ih;	if (pci_mapreg_map(pa, PCIIDE_REG_CMD_BASE(wdc_cp->channel),	    PCI_MAPREG_TYPE_IO, 0,	    &wdc_cp->cmd_iot, &wdc_cp->cmd_ioh, NULL, cmdsizep, 0) != 0) {		printf("%s: couldn't map %s cmd regs\n",		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);		return 0;	}	if (pci_mapreg_map(pa, PCIIDE_REG_CTL_BASE(wdc_cp->channel),	    PCI_MAPREG_TYPE_IO, 0,	    &wdc_cp->ctl_iot, &wdc_cp->ctl_ioh, NULL, ctlsizep, 0) != 0) {		printf("%s: couldn't map %s ctl regs\n",		    sc->sc_wdcdev.sc_dev.dv_xname, cp->name);		bus_space_unmap(wdc_cp->cmd_iot, wdc_cp->cmd_ioh, *cmdsizep);		return 0;	}	return (1);}voidpciide_mapreg_dma(sc, pa)	struct pciide_softc *sc;	struct pci_attach_args *pa;{#ifndef PMON	/*	 * Map DMA registers	 *	 * Note that sc_dma_ok is the right variable to test to see if	 * DMA can be done.  If the interface doesn't support DMA,	 * sc_dma_ok will never be non-zero.  If the DMA regs couldn't	 * be mapped, it'll be zero.  I.e., sc_dma_ok will only be	 * non-zero if the interface supports DMA and the registers	 * could be mapped.	 *	 * XXX Note that despite the fact that the Bus Master IDE specs	 * XXX say that "The bus master IDE function uses 16 bytes of IO	 * XXX space," some controllers (at least the United	 * XXX Microelectronics UM8886BF) place it in memory space.	 * XXX eventually, we should probably read the register and check	 * XXX which type it is.  Either that or 'quirk' certain devices.	 */	sc->sc_dma_ok = (pci_mapreg_map(pa,	    PCIIDE_REG_BUS_MASTER_DMA, PCI_MAPREG_TYPE_IO, 0,	    &sc->sc_dma_iot, &sc->sc_dma_ioh, NULL, NULL) == 0);	sc->sc_dmat = pa->pa_dmat;	if (sc->sc_dma_ok == 0) {		printf(", (unuseable)"); /* couldn't map registers */	} else {		sc->sc_wdcdev.dma_arg = sc;		sc->sc_wdcdev.dma_init = pciide_dma_init;		sc->sc_wdcdev.dma_start = pciide_dma_start;		sc->sc_wdcdev.dma_finish = pciide_dma_finish;	}#else	sc->sc_dma_ok = 0;#endif}intpciide_compat_intr(arg)	void *arg;{	struct pciide_channel *cp = arg;#ifdef DIAGNOSTIC	/* should only be called for a compat channel */	if (cp->compat == 0)		panic("pciide compat intr called for non-compat chan %p\n", cp);#endif	return (wdcintr(&cp->wdc_channel));}intpciide_pci_intr(arg)	void *arg;{	struct pciide_softc *sc = arg;	struct pciide_channel *cp;	struct channel_softc *wdc_cp;	int i, rv, crv;	rv = 0;	for (i = 0; i < sc->sc_wdcdev.nchannels; i++) {		cp = &sc->pciide_channels[i];		wdc_cp = &cp->wdc_channel;		/* If a compat channel skip. */		if (cp->compat)			continue;		/* if this channel not waiting for intr, skip */		if ((wdc_cp->ch_flags & WDCF_IRQ_WAIT) == 0)			continue;		crv = wdcintr(wdc_cp);		if (crv == 0)			;		/* leave rv alone */		else if (crv == 1)			rv = 1;		/* claim the intr */		else if (rv == 0)	/* crv should be -1 in this case */			rv = crv;	/* if we've done no better, take it */	}	return (rv);}#ifndef PMONvoidpciide_channel_dma_setup(cp)	struct pciide_channel *cp;{	int drive;	struct pciide_softc *sc = (struct pciide_softc *)cp->wdc_channel.wdc;	struct ata_drive_datas *drvp;	for (drive = 0; drive < 2; drive++) {		drvp = &cp->wdc_channel.ch_drive[drive];		/* If no drive, skip */		if ((drvp->drive_flags & DRIVE) == 0)			continue;		/* setup DMA if needed */		if (((drvp->drive_flags & DRIVE_DMA) == 0 &&		    (drvp->drive_flags & DRIVE_UDMA) == 0) ||		    sc->sc_dma_ok == 0) {			drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);			continue;		}		if (pciide_dma_table_setup(sc, cp->wdc_channel.channel, drive)		    != 0) {			/* Abort DMA setup */			drvp->drive_flags &= ~(DRIVE_DMA | DRIVE_UDMA);			continue;		}	}}intpciide_dma_table_setup(sc, channel, drive)	struct pciide_softc *sc;	int channel, drive;{	bus_dma_segment_t seg;	int error, rseg;	const bus_size_t dma_table_size =	    sizeof(struct idedma_table) * NIDEDMA_TABLES;	struct pciide_dma_maps *dma_maps =	    &sc->pciide_channels[channel].dma_maps[drive];	/* If table was already allocated, just return */	if (dma_maps->dma_table)		return 0;	/* Allocate memory for the DMA tables and map it */	if ((error = bus_dmamem_alloc(sc->sc_dmat, dma_table_size,	    IDEDMA_TBL_ALIGN, IDEDMA_TBL_ALIGN, &seg, 1, &rseg,	    BUS_DMA_NOWAIT)) != 0) {		printf("%s:%d: unable to allocate table DMA for "		    "drive %d, error=%d\n", sc->sc_wdcdev.sc_dev.dv_xname,		    channel, drive, error);		return error;	}	if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,	    dma_table_size,	    (caddr_t *)&dma_maps->dma_table,	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {		printf("%s:%d: unable to map table DMA for"		    "drive %d, error=%d\n", sc->sc_wdcdev.sc_dev.dv_xname,		    channel, drive, error);		return error;	}	WDCDEBUG_PRINT(("pciide_dma_table_setup: table at %p len %ld, "	    "phy 0x%lx\n", dma_maps->dma_table, dma_table_size,	    seg.ds_addr), DEBUG_PROBE);	/* Create and load table DMA map for this disk */	if ((error = bus_dmamap_create(sc->sc_dmat, dma_table_size,	    1, dma_table_size, IDEDMA_TBL_ALIGN, BUS_DMA_NOWAIT,	    &dma_maps->dmamap_table)) != 0) {		printf("%s:%d: unable to create table DMA map for "		    "drive %d, error=%d\n", sc->sc_wdcdev.sc_dev.dv_xname,		    channel, drive, error);		return error;	}	if ((error = bus_dmamap_load(sc->sc_dmat,	    dma_maps->dmamap_table,	    dma_maps->dma_table,	    dma_table_size, NULL, BUS_DMA_NOWAIT)) != 0) {		printf("%s:%d: unable to load table DMA map for "		    "drive %d, error=%d\n", sc->sc_wdcdev.sc_dev.dv_xname,		    channel, drive, error);		return error;	}	WDCDEBUG_PRINT(("pciide_dma_table_setup: phy addr of table 0x%lx\n",	    dma_maps->dmamap_table->dm_segs[0].ds_addr), DEBUG_PROBE);	/* Create a xfer DMA map for this drive */	if ((error = bus_dmamap_create(sc->sc_dmat, IDEDMA_BYTE_COUNT_MAX,	    NIDEDMA_TABLES, IDEDMA_BYTE_COUNT_MAX, IDEDMA_BYTE_COUNT_ALIGN,	    BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW,	    &dma_maps->dmamap_xfer)) != 0) {		printf("%s:%d: unable to create xfer DMA map for "		    "drive %d, error=%d\n", sc->sc_wdcdev.sc_dev.dv_xname,		    channel, drive, error);		return error;	}	return 0;}intpciide_dma_init(v, channel, drive, databuf, datalen, flags)	void *v;	int channel, drive;	void *databuf;	size_t datalen;	int flags;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -