Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 May 2005 00:23:46 -0300
From:      =?ISO-8859-1?Q?Lu=EDs_Vit=F3rio?= Cargnini <cargnini@cargnini.trix.net>
To:        freebsd-hackers@freebsd.org
Subject:   PCI Device Driver
Message-ID:  <1116559426.27848.7.camel@shark.hopto.org>

next in thread | raw e-mail | index | archive | help
Hi i need to write a device driver for a PCI board. I read the
developers book see the exemples and i'm starting to write the device
driver. I'm writeing a device driver for a board with SAA713X TV chipset
from Phillips. I did theskeleton example, but whe i catch the example of
PCI driver from developers book and tried to compilate i receive the
following:
(forgive me for the long paste, but i need some answers and i need to
give the details)


PASTE of ERORS:
@/sys/bus.h:455:23: device_if.h: No such file or directory
@/sys/bus.h:456:20: bus_if.h: No such file or directory
In file included from saa713x.c:23:
@/dev/pci/pcivar.h:170:20: pci_if.h: No such file or directory
In file included from saa713x.c:23:
@/dev/pci/pcivar.h: In function `pci_get_subvendor':
@/dev/pci/pcivar.h:203: warning: implicit declaration of function
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h: In function `pci_set_subvendor':
@/dev/pci/pcivar.h:203: warning: implicit declaration of function
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h: In function `pci_get_subdevice':
@/dev/pci/pcivar.h:204: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_subdevice':
@/dev/pci/pcivar.h:204: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_vendor':
@/dev/pci/pcivar.h:205: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_vendor':
@/dev/pci/pcivar.h:205: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_device':
@/dev/pci/pcivar.h:206: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_device':
@/dev/pci/pcivar.h:206: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_devid':
@/dev/pci/pcivar.h:207: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_devid':
@/dev/pci/pcivar.h:207: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_class':
@/dev/pci/pcivar.h:208: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_class':
@/dev/pci/pcivar.h:208: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_subclass':
@/dev/pci/pcivar.h:209: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_subclass':
@/dev/pci/pcivar.h:209: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_progif':
@/dev/pci/pcivar.h:210: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_progif':
@/dev/pci/pcivar.h:210: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_revid':
@/dev/pci/pcivar.h:211: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_revid':
@/dev/pci/pcivar.h:211: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_intpin':
@/dev/pci/pcivar.h:212: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_intpin':
@/dev/pci/pcivar.h:212: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_irq':
@/dev/pci/pcivar.h:213: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_irq':
@/dev/pci/pcivar.h:213: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_bus':
@/dev/pci/pcivar.h:214: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_bus':
@/dev/pci/pcivar.h:214: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_slot':
@/dev/pci/pcivar.h:215: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_slot':
@/dev/pci/pcivar.h:215: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_function':
@/dev/pci/pcivar.h:216: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_function':
@/dev/pci/pcivar.h:216: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_get_ether':
@/dev/pci/pcivar.h:217: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_set_ether':
@/dev/pci/pcivar.h:217: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_read_config':
@/dev/pci/pcivar.h:227: warning: implicit declaration of function
`PCI_READ_CONFIG'
@/dev/pci/pcivar.h:227: warning: nested extern declaration of
`PCI_READ_CONFIG'
@/dev/pci/pcivar.h: In function `pci_write_config':
@/dev/pci/pcivar.h:233: warning: implicit declaration of function
`PCI_WRITE_CONFIG'
@/dev/pci/pcivar.h:233: warning: nested extern declaration of
`PCI_WRITE_CONFIG'
@/dev/pci/pcivar.h: In function `pcib_get_bus':
@/dev/pci/pcivar.h:248: warning: nested extern declaration of
`BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_READ_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_READ_IVAR' was here
@/dev/pci/pcivar.h: In function `pcib_set_bus':
@/dev/pci/pcivar.h:248: warning: nested extern declaration of
`BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: redundant redeclaration of
'BUS_WRITE_IVAR'
@/dev/pci/pcivar.h:203: warning: previous implicit declaration of
'BUS_WRITE_IVAR' was here
@/dev/pci/pcivar.h: In function `pci_enable_busmaster':
@/dev/pci/pcivar.h:269: warning: implicit declaration of function
`PCI_ENABLE_BUSMASTER'
@/dev/pci/pcivar.h:269: warning: nested extern declaration of
`PCI_ENABLE_BUSMASTER'
@/dev/pci/pcivar.h: In function `pci_disable_busmaster':
@/dev/pci/pcivar.h:275: warning: implicit declaration of function
`PCI_DISABLE_BUSMASTER'
@/dev/pci/pcivar.h:275: warning: nested extern declaration of
`PCI_DISABLE_BUSMASTER'
@/dev/pci/pcivar.h: In function `pci_enable_io':
@/dev/pci/pcivar.h:281: warning: implicit declaration of function
`PCI_ENABLE_IO'
@/dev/pci/pcivar.h:281: warning: nested extern declaration of
`PCI_ENABLE_IO'
@/dev/pci/pcivar.h: In function `pci_disable_io':
@/dev/pci/pcivar.h:287: warning: implicit declaration of function
`PCI_DISABLE_IO'
@/dev/pci/pcivar.h:287: warning: nested extern declaration of
`PCI_DISABLE_IO'
@/dev/pci/pcivar.h: In function `pci_set_powerstate':
@/dev/pci/pcivar.h:314: warning: implicit declaration of function
`PCI_SET_POWERSTATE'
@/dev/pci/pcivar.h:314: warning: nested extern declaration of
`PCI_SET_POWERSTATE'
@/dev/pci/pcivar.h: In function `pci_get_powerstate':
@/dev/pci/pcivar.h:320: warning: implicit declaration of function
`PCI_GET_POWERSTATE'
@/dev/pci/pcivar.h:320: warning: nested extern declaration of
`PCI_GET_POWERSTATE'
saa713x.c: At top level:
saa713x.c:50: error: conflicting types for 'saa713x_open'
saa713x.c:27: error: previous declaration of 'saa713x_open' was here
saa713x.c:50: error: conflicting types for 'saa713x_open'
saa713x.c:27: error: previous declaration of 'saa713x_open' was here
saa713x.c:59: error: conflicting types for 'saa713x_close'
saa713x.c:28: error: previous declaration of 'saa713x_close' was here
saa713x.c:59: error: conflicting types for 'saa713x_close'
saa713x.c:28: error: previous declaration of 'saa713x_close' was here
saa713x.c:68: error: conflicting types for 'saa713x_read'
saa713x.c:29: error: previous declaration of 'saa713x_read' was here
saa713x.c:68: error: conflicting types for 'saa713x_read'
saa713x.c:29: error: previous declaration of 'saa713x_read' was here
saa713x.c:77: error: conflicting types for 'saa713x_write'
saa713x.c:30: error: previous declaration of 'saa713x_write' was here
saa713x.c:77: error: conflicting types for 'saa713x_write'
saa713x.c:30: error: previous declaration of 'saa713x_write' was here
saa713x.c: In function `saa713x_attach':
saa713x.c:111: warning: assignment makes integer from pointer without a
cast
saa713x.c: At top level:
saa713x.c:161: error: `device_probe_desc' undeclared here (not in a
function)
saa713x.c:161: error: initializer element is not constant
saa713x.c:161: error: (near initialization for
`saa713x_methods[0].desc')
saa713x.c:161: error: initializer element is not constant
saa713x.c:161: error: (near initialization for `saa713x_methods[0]')
saa713x.c:162: error: `device_attach_desc' undeclared here (not in a
function)
saa713x.c:162: error: initializer element is not constant
saa713x.c:162: error: (near initialization for
`saa713x_methods[1].desc')
saa713x.c:162: error: initializer element is not constant
saa713x.c:162: error: (near initialization for `saa713x_methods[1]')
saa713x.c:163: error: `device_detach_desc' undeclared here (not in a
function)
saa713x.c:163: error: initializer element is not constant
saa713x.c:163: error: (near initialization for
`saa713x_methods[2].desc')
saa713x.c:163: error: initializer element is not constant
saa713x.c:163: error: (near initialization for `saa713x_methods[2]')
saa713x.c:164: error: `device_shutdown_desc' undeclared here (not in a
function)
saa713x.c:164: error: initializer element is not constant
saa713x.c:164: error: (near initialization for
`saa713x_methods[3].desc')
saa713x.c:164: error: initializer element is not constant
saa713x.c:164: error: (near initialization for `saa713x_methods[3]')
saa713x.c:165: error: `device_suspend_desc' undeclared here (not in a
function)
saa713x.c:165: error: initializer element is not constant
saa713x.c:165: error: (near initialization for
`saa713x_methods[4].desc')
saa713x.c:165: error: initializer element is not constant
saa713x.c:165: error: (near initialization for `saa713x_methods[4]')
saa713x.c:166: error: `device_resume_desc' undeclared here (not in a
function)
saa713x.c:166: error: initializer element is not constant
saa713x.c:166: error: (near initialization for
`saa713x_methods[5].desc')
saa713x.c:166: error: initializer element is not constant
saa713x.c:166: error: (near initialization for `saa713x_methods[5]')
saa713x.c:168: error: initializer element is not constant
saa713x.c:168: error: (near initialization for `saa713x_methods[6]')
*** Error code 1

Stop in /usr/home/.../projects/FreeBSD/device_drivers/saa713X.


The source code is this:START STAGE
/*
 * SAA713X Phillips Chipset 
 *
 * 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/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 <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>

#include <dev/pci/pcivar.h> /* For get_pci macros! */
#include <dev/pci/pcireg.h>

/* Function prototypes */
d_open_t    saa713x_open;
d_close_t   saa713x_close;
d_read_t    saa713x_read;
d_write_t   saa713x_write;

/* Character device entry points */

static struct cdevsw saa713x_cdevsw = {
    .d_open =   saa713x_open,
    .d_close =  saa713x_close,
    .d_read =   saa713x_read,
    .d_write =  saa713x_write,
    .d_name =   "saa713x",
};

/* vars */
static dev_t sdev;

/* We're more interested in probe/attach than with
   open/close/read/write at this point */

int
saa713x_open(dev_t dev, int oflags, int devtype, d_thread_t *td)
{
    int err = 0;

    printf("Opened device \"saa713x\" successfully.\n");
    return (err);
}

int
saa713x_close(dev_t dev, int fflag, int devtype, d_thread_t *td)
{
    int err = 0;

    printf("Closing device \"saa713x.\"\n");
    return (err);
}

int
saa713x_read(dev_t dev, struct uio *uio, int ioflag)
{
    int err = 0;

    printf("saa713x read!\n");
    return (err);
}

int
saa713x_write(dev_t dev, struct uio *uio, int ioflag)
{
    int err = 0;

    printf("saa713x write!\n");
    return (err);
}

/* PCI Support Functions */

/*
 * Return identification string if this is device is ours.
 */
static int
saa713x_probe(device_t dev)
{
    device_printf(dev, "Saa713x Probe\nVendor ID : 0x%x\nDevice ID : 0x%
x\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);
    }
    return (ENXIO);
}

/* Attach function is only called if the probe is successful */

static int
saa713x_attach(device_t dev)
{

    printf("Saa713x Attach for : deviceID : 0x%x
\n",pci_get_vendor(dev));
    sdev = make_dev(&saa713x_cdevsw, 0, UID_ROOT,
        GID_WHEEL, 0600, "saa713x");
    printf("Saa713x device loaded.\n");
    return (ENXIO);
}

/* Detach device. */

static int
saa713x_detach(device_t dev)
{

    printf("Saa713x detach!\n");
    return (0);
}

/* Called during system shutdown after sync. */

static int
saa713x_shutdown(device_t dev)
{

    printf("Saa713x shutdown!\n");
    return (0);
}

/*
 * Device suspend routine.
 */
static int
saa713x_suspend(device_t dev)
{

    printf("Saa713x suspend!\n");
    return (0);
}

/*
 * Device resume routine.
 */

static int
saa713x_resume(device_t dev)
{

    printf("Saa713x resume!\n");
    return (0);
}

static device_method_t saa713x_methods[] = {
    /* Device interface */
    DEVMETHOD(device_probe,     saa713x_probe),
    DEVMETHOD(device_attach,    saa713x_attach),
    DEVMETHOD(device_detach,    saa713x_detach),
    DEVMETHOD(device_shutdown,  saa713x_shutdown),
    DEVMETHOD(device_suspend,   saa713x_suspend),
    DEVMETHOD(device_resume,    saa713x_resume),

    { 0, 0 }
};

static driver_t saa713x_driver = {
    "saa713x",
    saa713x_methods,
    0,
    /*  sizeof(struct saa713x_softc), */
};

static devclass_t saa713x_devclass;

DRIVER_MODULE(saa713x, pci, saa713x_driver, saa713x_devclass, 0, 0);

thanks for any help



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