Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Feb 2004 09:35:13 -0700 (MST)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        thefly@acaro.org
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: [Driver] SC1100 watchdog driver
Message-ID:  <20040225.093513.52665693.imp@bsdimp.com>
In-Reply-To: <20040224152900.26555.qmail@nexlab.it>
References:  <20040224152900.26555.qmail@nexlab.it>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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