13 #include <epicsVersion.h> 14 #include <epicsAssert.h> 15 #include <epicsTypes.h> 16 #include <epicsExport.h> 17 #include <epicsStdio.h> 24 static volatile void *diagbase;
25 static epicsUInt32 diaglen;
43 void pcidiagset(
int b,
int d,
int f,
int bar,
int vendor,
int device,
int exact)
56 printf(
"Looking for %x:%x.%x\n", b, d, f);
58 if(vendor==0 && !exact)
60 if(device==0 && !exact)
69 fprintf(stderr,
"Error searching\n");
74 fprintf(stderr,
"No such device\n");
78 printf(
"Mapping %x:%x.%x\n", loc.dev->bus, loc.dev->device, loc.dev->function);
82 fprintf(stderr,
"Failed to get BAR length\n");
88 fprintf(stderr,
"Failed to map BAR\n");
94 #if defined(__linux__) 95 printf(
"BAR %d from %p for %u bytes\n",bar, (
void*)diagbase, (
unsigned)diaglen);
97 printf(
"BAR %d from %p\n",bar, (
void*)diagbase);
102 static int check_args(
int dmod,
unsigned int offset,
unsigned int count)
110 fprintf(stderr,
"Invalid data width %d\n",dmod);
114 #if defined(__linux__) 115 if(offset>=diaglen || offset+count>diaglen) {
116 fprintf(stderr,
"Invalid offset and/or count\n");
125 epicsUInt32 tval = value;
126 volatile char* dptr = offset + (
volatile char*)diagbase;
129 fprintf(stderr,
"Run pcidiagset first\n");
133 if(check_args(dmod, offset, 1))
137 case 8:
iowrite8(dptr, tval);
break;
151 fprintf(stderr,
"Run pcidiagset first\n");
155 if(check_args(dmod, offset, count))
161 if(count==0) count=1;
163 for(i=0, dptr=offset+(
volatile char*)diagbase; i<count; i++, dptr+=dbytes) {
164 if ((i*dbytes)%16==0)
165 printf(
"\n0x%08x ",i*dbytes);
166 else if ((i*dbytes)%4==0)
170 case 8: tval=
ioread8(dptr); printf(
"%02x",tval);
break;
171 case 16: tval=
nat_ioread16(dptr);printf(
"%04x",tval);
break;
172 case 32: tval=
nat_ioread32(dptr);printf(
"%08x",tval);
break;
184 fprintf(stderr,
"Run pcidiagset first\n");
188 if(check_args(dmod, offset, count))
194 if(count==0) count=1;
196 for(;count && !err;offset+=dbytes,count--) {
200 printf(
"0x%04x ", offset);
202 case 8: err =
devPCIConfigRead8(diagdev, offset, &u8); printf(
"%02x\n", u8);
break;
203 case 16: err =
devPCIConfigRead16(diagdev, offset, &u16); printf(
"%04x\n", u16);
break;
204 case 32: err =
devPCIConfigRead32(diagdev, offset, &u32); printf(
"%08x\n", u32);
break;
206 fprintf(stderr,
"Invalid dmod %d, must be 8, 16, or 32\n", dmod);
211 fprintf(stderr,
"read error %d\n", err);
214 static const iocshArg pcidiagsetArg0 = {
"Bus",iocshArgInt};
215 static const iocshArg pcidiagsetArg1 = {
"Device",iocshArgInt};
216 static const iocshArg pcidiagsetArg2 = {
"Function",iocshArgInt};
217 static const iocshArg pcidiagsetArg3 = {
"BAR",iocshArgInt};
218 static const iocshArg pcidiagsetArg4 = {
"PCI vendor ID",iocshArgInt};
219 static const iocshArg pcidiagsetArg5 = {
"PCI device ID",iocshArgInt};
220 static const iocshArg pcidiagsetArg6 = {
"exact",iocshArgInt};
221 static const iocshArg *
const pcidiagsetArgs[7] =
222 {&pcidiagsetArg0,&pcidiagsetArg1,&pcidiagsetArg2,&pcidiagsetArg3,&pcidiagsetArg4,&pcidiagsetArg5,&pcidiagsetArg6};
223 static const iocshFuncDef pcidiagsetFuncDef =
224 {
"pcidiagset",7,pcidiagsetArgs};
226 static void pcidiagsetCall(
const iocshArgBuf *args)
228 pcidiagset(args[0].ival, args[1].ival, args[2].ival, args[3].ival, args[4].ival, args[5].ival, args[6].ival);
231 static const iocshArg pciwriteArg0 = {
"data width (8,16,32)",iocshArgInt};
232 static const iocshArg pciwriteArg1 = {
"offset",iocshArgInt};
233 static const iocshArg pciwriteArg2 = {
"value",iocshArgInt};
234 static const iocshArg *
const pciwriteArgs[3] =
235 {&pciwriteArg0,&pciwriteArg1,&pciwriteArg2};
236 static const iocshFuncDef pciwriteFuncDef =
237 {
"pciwrite",3,pciwriteArgs};
239 static void pciwriteCall(
const iocshArgBuf *args)
241 pciwrite(args[0].ival, args[1].ival, args[2].ival);
244 static const iocshArg pcireadArg0 = {
"data width (8,16,32)",iocshArgInt};
245 static const iocshArg pcireadArg1 = {
"offset",iocshArgInt};
246 static const iocshArg pcireadArg2 = {
"count",iocshArgInt};
247 static const iocshArg *
const pcireadArgs[3] =
248 {&pcireadArg0,&pcireadArg1,&pcireadArg2};
249 static const iocshFuncDef pcireadFuncDef =
250 {
"pciread",3,pcireadArgs};
252 static void pcireadCall(
const iocshArgBuf *args)
254 pciread(args[0].ival, args[1].ival, args[2].ival);
257 static const iocshArg pciconfreadArg0 = {
"data width (8,16,32)",iocshArgInt};
258 static const iocshArg pciconfreadArg1 = {
"offset",iocshArgInt};
259 static const iocshArg pciconfreadArg2 = {
"count",iocshArgInt};
260 static const iocshArg *
const pciconfreadArgs[3] =
261 {&pciconfreadArg0,&pciconfreadArg1,&pciconfreadArg2};
262 static const iocshFuncDef pciconfreadFuncDef =
263 {
"pciconfread",3,pciconfreadArgs};
265 static void pciconfreadCall(
const iocshArgBuf *args)
267 pciconfread(args[0].ival, args[1].ival, args[2].ival);
270 static void pcish(
void)
272 iocshRegister(&pciwriteFuncDef,pciwriteCall);
273 iocshRegister(&pcireadFuncDef,pcireadCall);
274 iocshRegister(&pciconfreadFuncDef,pciconfreadCall);
275 iocshRegister(&pcidiagsetFuncDef,pcidiagsetCall);
void pciconfread(int dmod, int offset, int count)
#define DEVPCI_END
The last item in a list of PCI IDS.
epicsExportRegistrar(pcish)
INLINE void nat_iowrite16(volatile void *addr, epicsUInt16 val)
Write two byte in host order. Not byte swapping.
void pcidiagset(int b, int d, int f, int bar, int vendor, int device, int exact)
INLINE epicsUInt32 nat_ioread32(volatile void *addr)
Read four bytes in host order. Not byte swapping.
void pciwrite(int dmod, int offset, int value)
#define DEVPCI_DEVICE_VENDOR(dev, vend)
int devPCIConfigRead8(const epicsPCIDevice *dev, unsigned offset, epicsUInt8 *pResult)
Read byte from configuration space.
INLINE epicsUInt16 nat_ioread16(volatile void *addr)
Read two bytes in host order. Not byte swapping.
INLINE void iowrite8(volatile void *addr, epicsUInt8 val)
Write a single byte.
int devPCIToLocalAddr(const epicsPCIDevice *curdev, unsigned int bar, volatile void **ppLocalAddr, unsigned int opt)
Get pointer to PCI BAR.
#define DEVPCI_ANY_VENDOR
int devPCIConfigRead16(const epicsPCIDevice *dev, unsigned offset, epicsUInt16 *pResult)
Read (16-bit) word from configuration space.
const epicsPCIDevice * dev
#define DEVPCI_ANY_DEVICE
INLINE epicsUInt8 ioread8(volatile void *addr)
Read a single byte.
int devPCIBarLen(const epicsPCIDevice *curdev, unsigned int bar, epicsUInt32 *len)
Find the size of a BAR.
int devPCIConfigRead32(const epicsPCIDevice *dev, unsigned offset, epicsUInt32 *pResult)
Read (32-bit) dword from configuration space.
void pciread(int dmod, int offset, int count)
int devPCIFindCB(const epicsPCIID *idlist, devPCISearchFn searchfn, void *arg, unsigned int opt)
PCI bus search w/ callback.
INLINE void nat_iowrite32(volatile void *addr, epicsUInt32 val)
Write four byte in host order. Not byte swapping.