[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: [Driver] SC1100 watchdog driver
From:       "M. Warner Losh" <imp () bsdimp ! com>
Date:       2004-02-25 16:35:13
Message-ID: 20040225.093513.52665693.imp () bsdimp ! com
[Download RAW message or body]

In message: <20040224152900.26555.qmail@nexlab.it>
            "Claudio Martella" <thefly@acaro.org> writes:
: Through the DEV_MODULE() macro i defined the loading routine and 
: used DRIVER_MODULE() macro to define the pci driver.
: My first doubt is if 
: it's legal to use both of them in the same file/driver. Should i use just 
: one of the two ways just the load routine and the ioctl/open/close routines, 
: or the ioctl/open/close routines and the attach/probe routines? The problem 
: exists because i don't know where to put my init stuff, the make_dev() calls 
: etc etc, if in the loading routine, or in attach() or wherever?

Don't use both.  It is extremely rare for one to need a loading
routine at all.  Just use the DRIVER_MODULE().  You can then use the
make_dev routine in your attach routine.

: My second question is kindly connected to the first one. In my driver i've 
: got to access some registers of the device through PCI. I find the 
: bus_space_read|write routines & C really annoying. Isn't there an easy way 
: to just read a double word from the register?

Many people just define a small macro to help them with the bus space
routines.

: And: As long as i don't know 
: how initialization of my driver works (if through attach() or loading 
: routine or whatever) i'm still confused on how to actually attach to the 
: device: if it's through the attach() it's no problem, i've got the dev 
: pointer, but if it's through the loading routing, do i have to do something 
: like pci_find_device(vendor_id, device_id)? 

You're thinking backwards, ala old school linux.  Your driver doesn't
go looking for hardware.  Instead, the pci bus enumerates all the
devices that it can find and then asks the drivers' probe routine if
that device is something they know about.  For a simple PCI device,
chances are good that your probe routine will look like:

static int
foo_probe(device_t dev)
{
	if (pci_get_vendor(dev) == 0x1234 &&
	    pci_get_device(dev) == 0x5678) {
		device_set_name("SC1100 watchdog");
		return 0;
	}
	return ENXIO;
}

Warner

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic