devLib2  2.12
devLibPCI.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2010 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * devLib2 is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
9  */
10 
11 #ifndef DEVLIBPCI_H_INC
12 #define DEVLIBPCI_H_INC 1
13 
14 #include <dbDefs.h>
15 #include <epicsTypes.h>
16 #include <devLib.h>
17 #include <shareLib.h>
18 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #define DEVLIBPCI_MAJOR 1
31 #define DEVLIBPCI_MINOR 3
55 typedef struct {
56  epicsUInt32 device, vendor;
57  epicsUInt32 sub_device, sub_vendor;
58  epicsUInt32 pci_class;
59  epicsUInt16 revision;
60 } epicsPCIID;
61 
62 #define DEVPCI_ANY_DEVICE 0x10000
63 #define DEVPCI_ANY_VENDOR 0x10000
64 #define DEVPCI_ANY_SUBDEVICE 0x10000
65 #define DEVPCI_ANY_SUBVENDOR 0x10000
66 #define DEVPCI_ANY_CLASS 0x1000000
67 #define DEVPCI_ANY_REVISION 0x100
68 
69 #define DEVPCI_LAST_DEVICE 0xffff0000
70 
72 #define DEVPCI_END {DEVPCI_LAST_DEVICE,0,0,0,0,0}
73 
74 #define DEVPCI_DEVICE_ANY() \
75 { DEVPCI_ANY_DEVICE, DEVPCI_ANY_VENDOR, \
76  DEVPCI_ANY_SUBDEVICE, DEVPCI_ANY_SUBVENDOR, \
77  DEVPCI_ANY_CLASS, DEVPCI_ANY_REVISION }
78 
79 #define DEVPCI_DEVICE_VENDOR(dev,vend) \
80 { dev, vend, DEVPCI_ANY_SUBDEVICE, DEVPCI_ANY_SUBVENDOR, \
81  DEVPCI_ANY_CLASS, DEVPCI_ANY_REVISION }
82 
83 #define DEVPCI_DEVICE_VENDOR_CLASS(dev,vend,pclass) \
84 { dev, vend, DEVPCI_ANY_SUBDEVICE, DEVPCI_ANY_SUBVENDOR, \
85  pclass, DEVPCI_ANY_REVISION }
86 
87 #define DEVPCI_SUBDEVICE_SUBVENDOR(dev,vend,sdev,svend) \
88 { dev, vend, sdev, svend, \
89  DEVPCI_ANY_CLASS, DEVPCI_ANY_REVISION }
90 
91 #define DEVPCI_SUBDEVICE_SUBVENDOR_CLASS(dev,vend,sdev,svend,revision,pclass) \
92 { dev, vend, sdev, svend, \
93  pclass, revision }
94 
95 #define DEVPCI_NO_SLOT NULL
96 
97 struct PCIBar {
98  unsigned int ioport:1;
99  unsigned int addr64:1;
100  unsigned int below1M:1;
101 };
102 
112 typedef struct {
114  unsigned int bus;
115  unsigned int device;
116  unsigned int function;
118  const char* slot;
119  struct PCIBar bar[6];
120  epicsUInt8 irq;
121  unsigned int domain;
122  const char* driver;
124 
126 #define PCIBARCOUNT NELEMENTS( ((epicsPCIDevice*)0)->bar )
127 
136 typedef int (*devPCISearchFn)(void* ptr,const epicsPCIDevice* dev);
137 
154 epicsShareFunc
155 int devPCIFindCB(
156  const epicsPCIID *idlist,
157  devPCISearchFn searchfn,
158  void *arg,
159  unsigned int opt /* always 0 */
160  );
161 
180 epicsShareFunc
181 int devPCIFindSpec(
182  const epicsPCIID *idlist,
183  const char *spec,
184  const epicsPCIDevice **found,
185  unsigned int opt /* always 0 */
186  );
187 
206 epicsShareFunc
207 int devPCIFindDBDF(
208  const epicsPCIID *idlist,
209  unsigned int domain,
210  unsigned int b,
211  unsigned int d,
212  unsigned int f,
213  const epicsPCIDevice **found,
214  unsigned int opt /* always 0 */
215  );
216 
217 epicsShareFunc
218 int devPCIFindBDF(
219  const epicsPCIID *idlist,
220  unsigned int b,
221  unsigned int d,
222  unsigned int f,
223  const epicsPCIDevice **found,
224  unsigned int opt /* always 0 */
225  );
226 
227 #ifdef __linux__
228 #define DEVLIB_MAP_UIO1TO1 0
229 #define DEVLIB_MAP_UIOCOMPACT 1
230 #else
231 /* UIO options have no meaning for non-Linux OSs */
232 #define DEVLIB_MAP_UIO1TO1 0
233 #define DEVLIB_MAP_UIOCOMPACT 0
234 #endif
235 
256 epicsShareFunc
257 int
259  const epicsPCIDevice *id,
260  unsigned int bar,
261  volatile void **ppLocalAddr,
262  unsigned int opt /* always 0 */
263  );
264 
279 epicsShareFunc
280 int
282  const epicsPCIDevice *id,
283  unsigned int bar,
284  epicsUInt32 *len
285  );
286 
305 epicsShareFunc
307  const epicsPCIDevice *id,
308  void (*pFunction)(void *),
309  void *parameter,
310  unsigned int opt /* always 0 */
311  );
312 
321 epicsShareFunc
323  const epicsPCIDevice *id,
324  void (*pFunction)(void *),
325  void *parameter
326  );
327 
328 epicsShareFunc
329 void
330 devPCIShow(int lvl, int vendor, int device, int exact);
331 
332 epicsShareFunc
333 void
334 devPCIShowMatch(int lvl, const char *spec, int vendor, int device);
335 
336 epicsShareFunc
337 void
338 devPCIShowDevice(int lvl, const epicsPCIDevice *dev);
339 
347 epicsShareFunc
348 int
349 devLibPCIUse(const char* name);
350 
351 epicsShareFunc
352 const char* devLibPCIDriverName();
353 
354 epicsShareExtern int devPCIDebug;
355 
364 epicsShareFunc
365 int devPCIConfigRead8(const epicsPCIDevice *dev, unsigned offset, epicsUInt8 *pResult);
366 
376 epicsShareFunc
377 int devPCIConfigRead16(const epicsPCIDevice *dev, unsigned offset, epicsUInt16 *pResult);
378 
387 epicsShareFunc
388 int devPCIConfigRead32(const epicsPCIDevice *dev, unsigned offset, epicsUInt32 *pResult);
389 
398 epicsShareFunc
399 int devPCIConfigWrite8(const epicsPCIDevice *dev, unsigned offset, epicsUInt8 value);
400 
410 epicsShareFunc
411 int devPCIConfigWrite16(const epicsPCIDevice *dev, unsigned offset, epicsUInt16 value);
412 
421 epicsShareFunc
422 int devPCIConfigWrite32(const epicsPCIDevice *dev, unsigned offset, epicsUInt32 value);
423 
431 epicsShareFunc
432 int devPCIEnableInterrupt(const epicsPCIDevice *dev);
433 
442 epicsShareFunc
443 int devPCIDisableInterrupt(const epicsPCIDevice *dev);
444 
451 epicsShareFunc
452 const char* devPCIDeviceClassToString(int classId);
453 
454 #ifdef __cplusplus
455 } /* extern "C" */
456 #endif
457 
460 #endif /* DEVLIBPCI_H_INC */
const char * driver
Definition: devLibPCI.h:122
int(* devPCISearchFn)(void *ptr, const epicsPCIDevice *dev)
PCI search callback prototype.
Definition: devLibPCI.h:136
epicsShareFunc int devPCIEnableInterrupt(const epicsPCIDevice *dev)
Enable interrupts at the device.
Definition: devLibPCI.c:640
epicsShareFunc const char * devLibPCIDriverName()
Definition: devLibPCI.c:138
epicsShareFunc int devPCIConnectInterrupt(const epicsPCIDevice *id, void(*pFunction)(void *), void *parameter, unsigned int opt)
Request interrupts for device.
Definition: devLibPCI.c:463
unsigned int ioport
Definition: devLibPCI.h:98
epicsShareFunc int devPCIConfigWrite32(const epicsPCIDevice *dev, unsigned offset, epicsUInt32 value)
Write (32-bit) dword from configuration space.
Definition: devLibPCI.c:633
epicsShareFunc int devPCIDisableInterrupt(const epicsPCIDevice *dev)
Enable interrupts at the device.
Definition: devLibPCI.c:649
epicsShareFunc int devPCIConfigWrite16(const epicsPCIDevice *dev, unsigned offset, epicsUInt16 value)
Write (16-bit) word from configuration space.
Definition: devLibPCI.c:627
unsigned int below1M
Definition: devLibPCI.h:100
epicsUInt32 sub_vendor
Definition: devLibPCI.h:57
unsigned int bus
Definition: devLibPCI.h:114
epicsUInt8 irq
Definition: devLibPCI.h:120
epicsShareFunc int devPCIConfigRead8(const epicsPCIDevice *dev, unsigned offset, epicsUInt8 *pResult)
Read byte from configuration space.
Definition: devLibPCI.c:603
epicsShareFunc int devPCIToLocalAddr(const epicsPCIDevice *id, unsigned int bar, volatile void **ppLocalAddr, unsigned int opt)
Get pointer to PCI BAR.
Definition: devLibPCI.c:431
epicsShareFunc void devPCIShowDevice(int lvl, const epicsPCIDevice *dev)
Definition: devLibPCI.c:541
epicsShareFunc void devPCIShowMatch(int lvl, const char *spec, int vendor, int device)
Definition: devLibPCI.c:522
Device token.
Definition: devLibPCI.h:112
epicsShareFunc int devPCIConfigRead16(const epicsPCIDevice *dev, unsigned offset, epicsUInt16 *pResult)
Read (16-bit) word from configuration space.
Definition: devLibPCI.c:609
unsigned int domain
Definition: devLibPCI.h:121
unsigned int device
Definition: devLibPCI.h:115
epicsShareFunc int devPCIFindDBDF(const epicsPCIID *idlist, unsigned int domain, unsigned int b, unsigned int d, unsigned int f, const epicsPCIDevice **found, unsigned int opt)
PCI bus probe.
Definition: devLibPCI.c:376
epicsShareFunc int devPCIFindSpec(const epicsPCIID *idlist, const char *spec, const epicsPCIDevice **found, unsigned int opt)
PCI bus search by specification string.
Definition: devLibPCI.c:267
epicsShareFunc int devPCIDisconnectInterrupt(const epicsPCIDevice *id, void(*pFunction)(void *), void *parameter)
Stop receiving interrupts.
Definition: devLibPCI.c:476
PCI device identifier.
Definition: devLibPCI.h:55
epicsShareFunc int devPCIConfigWrite8(const epicsPCIDevice *dev, unsigned offset, epicsUInt8 value)
Write byte to configuration space.
Definition: devLibPCI.c:621
unsigned int addr64
Definition: devLibPCI.h:99
epicsUInt16 revision
Definition: devLibPCI.h:59
const char * slot
Definition: devLibPCI.h:118
epicsShareFunc int devPCIFindBDF(const epicsPCIID *idlist, unsigned int b, unsigned int d, unsigned int f, const epicsPCIDevice **found, unsigned int opt)
Definition: devLibPCI.c:418
epicsShareFunc int devLibPCIUse(const char *name)
Select driver implementation. Pick driver implementation by name, or NULL to use default. If no selection is made then the default will be used if available.
Definition: devLibPCI.c:107
epicsShareFunc const char * devPCIDeviceClassToString(int classId)
Translate class id to string.
epicsShareFunc void devPCIShow(int lvl, int vendor, int device, int exact)
Definition: devLibPCI.c:504
epicsShareFunc int devPCIBarLen(const epicsPCIDevice *id, unsigned int bar, epicsUInt32 *len)
Find the size of a BAR.
Definition: devLibPCI.c:449
epicsPCIID id
Exact ID of device.
Definition: devLibPCI.h:113
epicsUInt32 pci_class
Definition: devLibPCI.h:58
epicsShareFunc int devPCIConfigRead32(const epicsPCIDevice *dev, unsigned offset, epicsUInt32 *pResult)
Read (32-bit) dword from configuration space.
Definition: devLibPCI.c:615
epicsShareExtern int devPCIDebug
Definition: devLibPCI.h:354
epicsUInt32 vendor
Definition: devLibPCI.h:56
epicsShareFunc int devPCIFindCB(const epicsPCIID *idlist, devPCISearchFn searchfn, void *arg, unsigned int opt)
PCI bus search w/ callback.
Definition: devLibPCI.c:214