Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Sep 2000 22:35:26 -0700
From:      Mike Smith <msmith@freebsd.org>
To:        papowell@astart.com
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Device driver, memory map failing, and it is probably obvious 
Message-ID:  <200009200535.WAA02187@mass.osd.bsdi.com>
In-Reply-To: Your message of "Sun, 17 Sep 2000 19:20:43 PDT." <200009180220.TAA12263@h4.private> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > found 'Digi International PCI Classic 8 Serial Adapter'
> > my0: <Digi International PCI Classic 8 Serial Adapter> \
>    port 0xdc00-0xdcff,0xd800-0xd87f mem 0xea400000-0xea4000ff,0xea402000-0xea40207f \
>     irq 12 at device 10.0 on pci0
> > digic_attach: unit 0, irq 12, slot 10, progif 0x0, iobase 0xd801, membase 0xea402000, irqline 0x10c
> > my0: couldn't map memory
> > device_probe_and_attach: my0 attach returned 6
> 
> So it found the card, discovered the vintage hardware id, and printed it out.
> The we call the attach routine:
> 
> > static int
> > digic_attach( device_t dev )
> > {
> > 	struct digic_softc *digic;
> > 	int unit;
> > 	int irq, slot, progif, iobase, membase, irqline;
> > 	int error = 0;
> > 	void *ih = 0;
> > 
> > 	/* get the sc structure */
> > 	digic = device_get_softc(dev);
> > 	bzero(digic,sizeof(digic[0]));

	bzero(digic, sizeof(*digic))

> > 	unit = device_get_unit(dev);

Don't use this; use device_printf();

> > 	irq = pci_get_irq(dev);
> > 	slot = pci_get_slot(dev);

You don't need these.

> > 	progif = pci_get_progif(dev);

And you probably don't want that.

> > #define WB_PCI_LOMEM	0x10
> > #define WB_PCI_LOIO	0x14
> > #define WB_PCI_INTLINE	0x3c
> > 	iobase = pci_read_config(dev, WB_PCI_LOIO, 4);
> > 	membase = pci_read_config(dev, WB_PCI_LOMEM, 4);
> > 	irqline = pci_read_config(dev, WB_PCI_INTLINE, 4);

You don't need these.

> > 	DPRINTF(("digic_attach: unit %d, irq %d, slot %d, progif 0x%x, iobase 0x%x, membase 0x%x, irqline 0x%x\n",
> > 		unit, irq, slot, progif, iobase, membase, irqline ));

Use device_printf().

> > 	
> > 	switch( pci_get_device(dev) ){
> > 		case PCI_CLASSIC_4: digic->digic_ports = 4; break;
> > 		case PCI_CLASSIC_8: digic->digic_ports = 8; break;
> > 		default:
> > 			device_printf(dev,"digic_attach: bad device id! %d", pci_get_device(dev));
> > 			goto fail;
> > 	}
> > 
> > 	/* now get the memory resources */
> > 	digic->digic_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
> > 					    &digic->digic_mem_rid,
> > 					    0, ~0, 256, RF_ACTIVE|RF_SHAREABLE);

You have to initialise digic->digic_mem_rid first.  Looking at the above, 
I'd guess it should be initialised to WB_PCI_LOMEM, which should actually 
be PCIR_MAPS.

> > 	if (!digic->digic_mem_res) {
> > 		device_printf(dev, "couldn't map memory\n");
> > 		goto fail;
> > 	}
> 
> Now, I am SURE that I must be doing something stupid here - but I snipped this code
> right out of the code for another driver,  and this one works.
> 
> The only puzzle is:
> > my0: <Digi International PCI Classic 8 Serial Adapter> \
>    port 0xdc00-0xdcff,0xd800-0xd87f mem 0xea400000-0xea4000ff,0xea402000-0xea40207f \
>     irq 12 at device 10.0 on pci0
> 
> Note that the diagnostic output indicates some VERY strange ranges.
> Could this be the problem?

I wouldn't say that any of these ranges are strange at all.  You have a 
256-byte and a 128-byte window in each of I/O and memory space.  Looks 
fine to me.



-- 
... every activity meets with opposition, everyone who acts has his
rivals and unfortunately opponents also.  But not because people want
to be opponents, rather because the tasks and relationships force
people to take different points of view.  [Dr. Fritz Todt]




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009200535.WAA02187>