Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Jan 2001 14:26:02 -0800
From:      Mike Smith <msmith@freebsd.org>
To:        "David E. Cross" <crossd@intrepid.cs.rpi.edu>
Cc:        hackers@freebsd.org
Subject:   Re: Device Driver Question (bus_set_resource) 
Message-ID:  <200101172226.f0HMQ2Q00442@mass.osd.bsdi.com>
In-Reply-To: Your message of "Wed, 17 Jan 2001 10:55:52 EST." <200101171555.KAA03762@cs.rpi.edu> 

next in thread | previous in thread | raw e-mail | index | archive | help

You're doing this "all wrong". 8)

If you know what the device's settings are, you want an identify routine 
which will create the device instance and set up resources for it.

If you want the user to be able to tweak the settings, you want a set of 
device hints and a normal ISA probe routine.

What you've written here is a confused bastardisation of the two, as well 
as confusing things with a call to ISA_PNP_PROBE.  

I'm sorry I can't be more explicit, what you've done is so totally 
confused that I can't just point at one thing and say "there's your 
mistake". 8)

> I am writing a simple, I/O only device driver (no lectures about /dev/io
> please ;).  It has not PnP abilities, and I have run into the following
> problem with bus_set_resource():  
> 
> static int das1400adc_isa_probe(device_t dev)
> {
>         struct das1400adc_softc *sc = device_get_softc(dev);
>         int unit = device_get_unit(dev);
>         int pnperror;
> 
>         sc->dev=dev;
>         sc->unit=unit;
>         sc->port0=DAS1400ADC_PORT;
>         sc->port1=sc->port0+11;
>         sc->port2=sc->port0+0x406;
>         sc->irq0=0;
>         sc->port0_rid=0;
>         sc->port1_rid=0;
>         sc->port2_rid=0;
>         sc->low=sc->high=0;
>         
>         pnperror=ISA_PNP_PROBE(device_get_parent(dev), dev, das1400adc_pnp_ids);
>         if (pnperror != ENXIO)
>                 return pnperror;
> 
>         if (bus_set_resource(dev, SYS_RES_IOPORT, /*rid*/sc->port0_rid,
>                 sc->port0, 3) < 0)
>                 return ENXIO;
> /*      if (bus_set_resource(dev, SYS_RES_IOPORT, sc->port1_rid,
>                 sc->port1, 1) < 0)
>                 return ENXIO;
>         if (bus_set_resource(dev, SYS_RES_IOPORT, sc->port2_rid,
>                 sc->port2, 1) < 0)
>                 return ENXIO;
> */
>         device_set_desc(dev, "CIO-DAS1400-ADC");
>         return 0;     /* all is good */
> }
> 
> static int das1400adc_isa_attach(device_t dev)
> {
>         struct das1400adc_softc *sc = device_get_softc(dev);
> 
>         sc->port0_r = bus_alloc_resource(dev, SYS_RES_IOPORT, 
>                         &sc->port0_rid, /*start*/0, /*end*/ ~0, /*count*/ 0,
>                         RF_ACTIVE);
> 
> /*      sc->port1_r = bus_alloc_resource(dev, SYS_RES_IOPORT,
>                         &sc->port1_rid, 0, ~0, 0,
>                         RF_ACTIVE);
> 
>         sc->port2_r = bus_alloc_resource(dev, SYS_RES_IOPORT,
>                         &sc->port2_rid, 0, ~0, 0,
>                         RF_ACTIVE);
> */
>         if (sc->port0_r == NULL )
> /* || sc->port1_r == NULL )
>                 sc->port2_r == NULL)
> */
>                 return ENXIO;
> 
>         sc->md_dev=make_dev(&das1400adc_cdevsw, 0, 0, 0, 0600, "adc0");
>         sc->open_count=0;
>         return 0;       
> }
> 
> 
> 
> 
> Given that code, I get the following attach messages from the kernel:
> 
> "das1400adc2: <CIO-DAS1400-ADC> at port 0x310-0x312 irq 5 drq 1,5 on isa0"
> Uhm... I set neither the IRQ nor the drq... where does it get these from, and
> how can I get it to "do the right thing"?  Also, If I uncomment the settings
> for the additional ranges "really weird things" start to happen.  An example
> of 'weirdness' is that exact same code, when kldload-ed will attach a totally
> different device. 
> 
> Oh yeah, this is under 4.2-STABLE from 20010103.
> 
> --
> David Cross                               | email: crossd@cs.rpi.edu 
> Lab Director                              | Rm: 308 Lally Hall
> Rensselaer Polytechnic Institute,         | Ph: 518.276.2860            
> Department of Computer Science            | Fax: 518.276.4033
> I speak only for myself.                  | WinNT:Linux::Linux:FreeBSD
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message

-- 
... 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]
           V I C T O R Y   N O T   V E N G E A N C E




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?200101172226.f0HMQ2Q00442>