From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 25 08:36:26 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 59F6116A4D0 for ; Wed, 25 Feb 2004 08:36:26 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id D0F9943D31 for ; Wed, 25 Feb 2004 08:36:25 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.10/8.12.9) with ESMTP id i1PGaLkj061408; Wed, 25 Feb 2004 09:36:22 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Wed, 25 Feb 2004 09:35:13 -0700 (MST) Message-Id: <20040225.093513.52665693.imp@bsdimp.com> To: thefly@acaro.org From: "M. Warner Losh" In-Reply-To: <20040224152900.26555.qmail@nexlab.it> References: <20040224152900.26555.qmail@nexlab.it> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org Subject: Re: [Driver] SC1100 watchdog driver X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Feb 2004 16:36:26 -0000 In message: <20040224152900.26555.qmail@nexlab.it> "Claudio Martella" 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