From marius.nuennerich@gmx.net Thu Dec 22 23:00:46 2005 Return-Path: Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 73B2716A41F for ; Thu, 22 Dec 2005 23:00:46 +0000 (GMT) (envelope-from marius.nuennerich@gmx.net) Received: from mail.gmx.net (mail.gmx.de [213.165.64.21]) by mx1.FreeBSD.org (Postfix) with SMTP id 8041C43D58 for ; Thu, 22 Dec 2005 23:00:44 +0000 (GMT) (envelope-from marius.nuennerich@gmx.net) Received: (qmail invoked by alias); 22 Dec 2005 23:00:43 -0000 Received: from p5083823A.dip0.t-ipconnect.de (EHLO sol.hackerzberg.local) [80.131.130.58] by mail.gmx.net (mp030) with SMTP; 23 Dec 2005 00:00:43 +0100 Message-Id: <1135292443.0@sol.hackerzberg.local> Date: Fri, 23 Dec 2005 00:00:43 +0100 From: "Marius Nuennerich" To: "FreeBSD gnats submit" Subject: Update for books/arch-handbook/pci X-Send-Pr-Version: gtk-send-pr 0.4.6 X-GNATS-Notify: >Number: 90830 >Category: docs >Synopsis: [patch] update for books/arch-handbook/pci >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: closed >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Thu Dec 22 23:10:02 GMT 2005 >Closed-Date: Fri Jan 06 22:05:16 GMT 2006 >Last-Modified: Fri Jan 06 22:05:16 GMT 2006 >Originator: Marius Nuennerich >Release: FreeBSD 5.4-RELEASE-p5 i386 >Organization: >Environment: >Description: The attached patch is an update to the PCI chapter in the Architecture Handbook. I tried to compile the old code but that isn't possible anymore because of phk's dev_t -> struct cdev * change. Being new to PCI programming I changed a few other things in the sample that confused me and that I learned while reading other documentation about the topic. Being also new to docbook my xml probably isn't the best. >How-To-Repeat: >Fix: --- pci.diff begins here --- --- chapter.sgml.bak Sun Dec 18 23:13:36 2005 +++ chapter.sgml Thu Dec 22 23:38:34 2005 @@ -18,138 +18,131 @@ Information here about how the PCI bus code iterates through the unattached devices and see if a newly loaded kld will attach to any of them. + + Sample code: -/* + /* * Simple KLD to play with the PCI functions. * * Murray Stokely */ -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) - #include <sys/param.h> /* defines used in kernel.h */ #include <sys/module.h> #include <sys/systm.h> -#include <sys/errno.h> +#include <sys/errno.h> /* ENXIO */ #include <sys/kernel.h> /* types used in module initialization */ #include <sys/conf.h> /* cdevsw struct */ #include <sys/uio.h> /* uio struct */ #include <sys/malloc.h> -#include <sys/bus.h> /* structs, prototypes for pci bus stuff */ +#include <sys/bus.h> /* structs, prototypes for pci bus stuff */ #include <machine/bus.h> #include <sys/rman.h> #include <machine/resource.h> -#include <dev/pci/pcivar.h> /* For get_pci macros! */ +#include <dev/pci/pcivar.h> /* For pci_get macros! */ #include <dev/pci/pcireg.h> /* Function prototypes */ -d_open_t mypci_open; -d_close_t mypci_close; -d_read_t mypci_read; -d_write_t mypci_write; +static d_open_t mypci_open; +static d_close_t mypci_close; +static d_read_t mypci_read; +static d_write_t mypci_write; /* Character device entry points */ - static struct cdevsw mypci_cdevsw = { .d_open = mypci_open, .d_close = mypci_close, .d_read = mypci_read, .d_write = mypci_write, - .d_name = "mypci", + .d_name = "mypci" }; /* vars */ -static dev_t sdev; +static struct cdev *mypci_dev; /* for make_dev */ -/* We're more interested in probe/attach than with - open/close/read/write at this point */ +/* + * We're more interested in probe/attach than with + * open/close/read/write at this point + */ -int -mypci_open(dev_t dev, int oflags, int devtype, d_thread_t *td) +static int +mypci_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td) { - int err = 0; - - printf("Opened device \"mypci\" successfully.\n"); - return (err); + printf("mypci: open!\n"); + return (0); } -int -mypci_close(dev_t dev, int fflag, int devtype, d_thread_t *td) +static int +mypci_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td) { - int err = 0; - - printf("Closing device \"mypci.\"\n"); - return (err); + printf("mypci: close!\n"); + return (0); } -int -mypci_read(dev_t dev, struct uio *uio, int ioflag) +static int +mypci_read(struct cdev *dev, struct uio *uio, int ioflag) { - int err = 0; - - printf("mypci read!\n"); - return (err); + printf("mypci: read!\n"); + return (0); } -int -mypci_write(dev_t dev, struct uio *uio, int ioflag) +static int +mypci_write(struct cdev *dev, struct uio *uio, int ioflag) { - int err = 0; - - printf("mypci write!\n"); - return (err); + printf("mypci: write!\n"); + return (0); } /* PCI Support Functions */ /* - * Return identification string if this is device is ours. + * Print identification string if this device is ours. */ static int mypci_probe(device_t dev) { - device_printf(dev, "MyPCI Probe\nVendor ID : 0x%x\nDevice ID : 0x%x\n", + device_printf(dev, "probe: VendorID: 0x%04x DeviceID: 0x%04x\n", pci_get_vendor(dev), pci_get_device(dev)); if (pci_get_vendor(dev) == 0x11c1) { - printf("We've got the Winmodem, probe successful!\n"); - return (0); + device_printf(dev, "We've got the Winmodem, probe successful!\n"); + device_set_desc(dev, "Winmodem"); + return (BUS_PROBE_DEFAULT); } return (ENXIO); } -/* Attach function is only called if the probe is successful */ - +/* + * Attach function is only called if the probe is successful. + */ static int mypci_attach(device_t dev) { - - printf("MyPCI Attach for : deviceID : 0x%x\n",pci_get_vendor(dev)); - sdev = make_dev(&mypci_cdevsw, 0, UID_ROOT, + device_printf(dev, "attach: DeviceID: 0x%04x\n", pci_get_device(dev)); + mypci_dev = make_dev(&mypci_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "mypci"); - printf("Mypci device loaded.\n"); - return (ENXIO); + return (0); } -/* Detach device. */ - +/* + * Detach device. + */ static int mypci_detach(device_t dev) { - - printf("Mypci detach!\n"); + device_printf(dev, "detach!\n"); return (0); } -/* Called during system shutdown after sync. */ - +/* + * Called during system shutdown after sync. + */ static int mypci_shutdown(device_t dev) { - - printf("Mypci shutdown!\n"); + device_printf(dev, "shutdown!\n"); return (0); } @@ -159,20 +152,17 @@ static int mypci_suspend(device_t dev) { - - printf("Mypci suspend!\n"); + device_printf(dev, "suspend!\n"); return (0); } /* * Device resume routine. */ - static int mypci_resume(device_t dev) { - - printf("Mypci resume!\n"); + device_printf(dev, "resume!\n"); return (0); } @@ -191,24 +181,41 @@ static driver_t mypci_driver = { "mypci", mypci_methods, - 0, - /* sizeof(struct mypci_softc), */ + 0 /* sizeof(struct mypci_softc) */ }; static devclass_t mypci_devclass; DRIVER_MODULE(mypci, pci, mypci_driver, mypci_devclass, 0, 0); - Additional Resources - - PCI - Special Interest Group + + + Makefile + + KMOD=mypci +SRCS=mypci.c +SRCS+=device_if.h bus_if.h pci_if.h + +.include <bsd.kmod.mk> + + Simply running make with the above + Makefile + will create a file mypci.ko that can + be loaded into your system by typing: + &prompt.root; kldload ./mypci.ko + + + + Additional Resources + + PCI + Special Interest Group - PCI System Architecture, Fourth Edition by - Tom Shanley, et al. + PCI System Architecture, Fourth Edition by + Tom Shanley, et al. - - + + --- pci.diff ends here --- >Release-Note: >Audit-Trail: From: John Baldwin To: freebsd-doc@freebsd.org Cc: "Marius Nuennerich" , "FreeBSD gnats submit" Subject: Re: docs/90830: Update for books/arch-handbook/pci Date: Fri, 6 Jan 2006 16:25:25 -0500 On Thursday 22 December 2005 06:00 pm, Marius Nuennerich wrote: > >Number: 90830 > >Category: docs > >Synopsis: Update for books/arch-handbook/pci > >Confidential: no > >Severity: non-critical > >Priority: low > >Responsible: freebsd-doc > >State: open > >Quarter: > >Keywords: > >Date-Required: > >Class: doc-bug > >Submitter-Id: current-users > >Arrival-Date: Thu Dec 22 23:10:02 GMT 2005 > >Closed-Date: > >Last-Modified: > >Originator: Marius Nuennerich > >Release: FreeBSD 5.4-RELEASE-p5 i386 > >Organization: > >Environment: > > > > > > > > > > > >Description: > > The attached patch is an update to the PCI chapter in the Architecture > Handbook. I tried to compile the old code but that isn't possible anymore > because of phk's dev_t -> struct cdev * change. Being new to PCI > programming I changed a few other things in the sample that confused me and > that I learned while reading other documentation about the topic. > Being also new to docbook my xml probably isn't the best. Thanks for the updates. I've applied some of them and made some additional changes myself. The sample was missing D_VERSION which means it wouldn't have actually worked either. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org State-Changed-From-To: open->closed State-Changed-By: jhb State-Changed-When: Fri Jan 6 22:04:54 UTC 2006 State-Changed-Why: Patch committed (with some additional changes). http://www.freebsd.org/cgi/query-pr.cgi?pr=90830 >Unformatted: