--- ../picturebook.old/pci_freebsd.c Mon Dec 25 19:09:23 2000 +++ pci_freebsd.c Mon Dec 25 19:03:20 2000 @@ -0,0 +1,148 @@ +/* manipulate PCI devices from user space + + Tridge, July 2000 +*/ +/* + Copyright (C) Andrew Tridgell 2000 + Copyright (C) Takanori Watanabe 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "capture.h" +#include +#include +#include +#define MAX_BUS 8 + +#define PCI_GETCONF_MATCH_VENDDEV (PCI_GETCONF_MATCH_VENDOR|PCI_GETCONF_MATCH_DEVICE) +#define MAXHANDLE 32 + +static struct pci_io pio[MAXHANDLE]; +static u_int32_t handlebmp=0; +static int pci_fd=-1; +static int pcifd_internal_init(); +int pcifd_internal_init() +{ + return pci_fd=open("/dev/pci",O_RDWR,0); +} +/* find a PCI device and return a handle to it */ +int pci_find_device(u32 vendor, u32 device) +{ + + struct pci_conf pc[4];/*I think only one is enough*/ + struct pci_conf_io pcfi; + struct pci_match_conf pmc={{0,0,0},"",0,0xffff,0xffff,0, + PCI_GETCONF_MATCH_VENDDEV}; + int handle; + if(pci_fd==-1){ + if(pcifd_internal_init()==-1) + return -1; + } + pmc.pc_vendor=vendor; + pmc.pc_device=device; + pcfi.pat_buf_len=sizeof(pmc); + pcfi.num_patterns=1; + pcfi.patterns=&pmc; + pcfi.match_buf_len=sizeof(pc); + pcfi.num_matches=0; + pcfi.matches=pc; + pcfi.offset=0; + pcfi.generation=0; + ioctl(pci_fd,PCIOCGETCONF,&pcfi); + if(pcfi.num_matches==0){ + goto error; + } + for(handle=0;handle<32;handle++){ + if(!(handlebmp&(1<