devLib2  2.11
devcsr.c
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 #include <stdio.h>
12 
13 #include <errlog.h>
14 #include "devLib.h"
15 #define epicsExportSharedSymbols
16 #include "devcsr.h"
17 
18 volatile unsigned char* devCSRProbeSlot(int slot)
19 {
20  volatile unsigned char* addr;
21  char cr[3];
22 
23  if(slot<0 || slot>VMECSRSLOTMAX){
24  errlogPrintf("VME slot number out of range\n");
25  return NULL;
26  }
27 
29  atVMECSR,
30  CSRSlotBase(slot),
31  (volatile void**)(void*)&addr) )
32  {
33 
34  errlogPrintf("Failed to map slot %d to CR/CSR address 0x%08lx\n",slot,
35  (unsigned long)CSRSlotBase(slot));
36  return NULL;
37  }
38 
39  if( devReadProbe(1, addr+CR_ASCII_C, &cr[0]) ){
40  errlogPrintf("No card in slot %d\n",slot);
41  return NULL;
42  }
43 
44  cr[1]=*(addr+CR_ASCII_R);
45  cr[2]='\0';
46 
47  if( cr[0]!='C' || cr[1]!='R' ){
48  errlogPrintf("Card in slot %d has non-standard CR layout. Ignoring...\n",slot);
49  return NULL;
50  }
51 
52  return addr;
53 }
54 
55 /*
56  * @return 0 Not match
57  * @return 1 Match
58  */
59 static
60 int csrMatch(const struct VMECSRID* A, const struct VMECSRID* B)
61 {
62  if( A->vendor!=B->vendor &&
63  A->vendor!=VMECSRANY &&
64  B->vendor!=VMECSRANY
65  )
66  return 0;
67 
68  if( A->board!=B->board &&
69  A->board!=VMECSRANY &&
70  B->board!=VMECSRANY
71  )
72  return 0;
73 
74  if( A->revision!=B->revision &&
75  A->revision!=VMECSRANY &&
77  )
78  return 0;
79 
80  return 1;
81 }
82 
83 volatile unsigned char* devCSRTestSlot(
84  const struct VMECSRID* devs,
85  int slot,
86  struct VMECSRID* info
87  )
88 {
89  struct VMECSRID test;
90  volatile unsigned char* addr=devCSRProbeSlot(slot);
91 
92  if(!addr) return addr;
93 
94  test.vendor=CSRRead24(addr + CR_IEEE_OUI);
95  test.board=CSRRead32(addr + CR_BOARD_ID);
96  test.revision=CSRRead32(addr + CR_REVISION_ID);
97 
98  for(; devs && devs->vendor; devs++){
99  if(csrMatch(devs,&test)){
100  if(!!info){
101  info->vendor=test.vendor;
102  info->board=test.board;
103  info->revision=test.revision;
104  }
105  return addr;
106  }
107  }
108 
109  return NULL;
110 }
111 
112 /* Decode contents of CSR/CR and print to screen.
113  *
114  * v=0 - basic identification info (vendor/board id)
115  * v=1 - config/capability info
116  * v=2 - hex dump of start of CR
117  */
118 
119 void vmecsrprint(int N,int v)
120 {
121  volatile unsigned char* addr;
122  char ctrlsts=0;
123  int space;
124 
125  if( N<0 || N>=32 ){
126  errlogPrintf("Slot number of of range (1-31)\n");
127  return;
128  }
129 
130  errlogPrintf("====== Slot %d\n",N);
131 
132  addr=devCSRProbeSlot(N);
133  if(!addr) return;
134 
135  if(v>=2){
136  unsigned i;
137  for(i=0;i<512;i++){
138  if(i%16==0) {
139  printf("%04x: ",i);
140  }
141 
142  printf("%02x", ((int)*(addr+i))&0xff);
143 
144  if(i%16==15)
145  printf("\n");
146  else if(i%4==3)
147  printf(" ");
148  }
149  }
150 
151  if(v>=1){
152  errlogPrintf("ROM Checksum : 0x%02x\n",CSRRead8(addr + CR_ROM_CHECKSUM));
153  errlogPrintf("ROM Length : 0x%06x\n",CSRRead24(addr + CR_ROM_LENGTH));
154  errlogPrintf("CR data width: 0x%02x\n",CSRRead8(addr + CR_DATA_ACCESS_WIDTH));
155  errlogPrintf("CSR data width:0x%02x\n",CSRRead8(addr + CSR_DATA_ACCESS_WIDTH));
156  }
157 
158  space=CSRRead8(addr + CR_SPACE_ID);
159  errlogPrintf("CR space id: ");
160  if(space==1)
161  errlogPrintf("VME64\n");
162  else if(space==2)
163  errlogPrintf("VME64x\n");
164  else
165  errlogPrintf("Unknown (0x%02x)\n",space);
166 
167  errlogFlush();
168 
169  if(space>=1){
170  errlogPrintf("Vendor ID : 0x%06x\n",CSRRead24(addr + CR_IEEE_OUI));
171  errlogPrintf("Board ID : 0x%08x\n",CSRRead32(addr + CR_BOARD_ID));
172  errlogPrintf("Revision ID : 0x%08x\n",CSRRead32(addr + CR_REVISION_ID));
173  errlogPrintf("Program ID : 0x%02x\n",CSRRead8(addr + CR_PROGRAM_ID));
174 
175  errlogPrintf("CSR Bar : 0x%02x\n",CSRRead8(addr + CSR_BAR));
176  ctrlsts=CSRRead8(addr + CSR_BIT_SET);
177  errlogPrintf("CSR CS : 0x%02x\n",ctrlsts);
178  errlogPrintf("CSR Reset : %s\n",(ctrlsts&CSR_BITSET_RESET_MODE)?"Yes":"No");
179  errlogPrintf("CSR Sysfail : %s\n",(ctrlsts&CSR_BITSET_SYSFAIL_ENA)?"Yes":"No");
180  errlogPrintf("CSR Fail : %s\n",(ctrlsts&CSR_BITSET_MODULE_FAIL)?"Yes":"No");
181  errlogPrintf("CSR Enabled : %s\n",(ctrlsts&CSR_BITSET_MODULE_ENA)?"Yes":"No");
182  errlogPrintf("CSR Bus Err : %s\n",(ctrlsts&CSR_BITSET_BERR)?"Yes":"No");
183  }
184 
185  if(space>=2){
186  unsigned i;
187  errlogPrintf("User CR : %08x -> %08x\n",
188  CSRRead24(addr + CR_BEG_UCR),CSRRead24(addr + CR_END_UCR));
189  errlogPrintf("User CSR : %08x -> %08x\n",
190  CSRRead24(addr + CR_BEG_UCSR),CSRRead24(addr + CR_END_UCSR));
191  errlogPrintf("CSR Owned : %s\n",(ctrlsts&CSR_BITSET_CRAM_OWNED)?"Yes":"No");
192  errlogPrintf("Owner : 0x%02x\n",CSRRead8(addr + CSR_CRAM_OWNER));
193  errlogPrintf("User bits : 0x%02x\n",CSRRead8(addr + CSR_UD_BIT_SET));
194  errlogPrintf("Serial Number: 0x");
195  for(i=CR_BEG_SN; i<=CR_END_SN; i+=4)
196  errlogPrintf("%02x",CSRRead8(addr + i));
197  errlogPrintf("\n");
198  if(v>=1){
199  errlogFlush();
200  errlogPrintf("Master Cap. : 0x%02x\n",CSRRead16(addr + CR_MASTER_CHAR));
201  errlogPrintf("Slave Cap. : 0x%02x\n",CSRRead16(addr + CR_SLAVE_CHAR));
202  errlogPrintf("IRQ Sink Cap.: 0x%02x\n",CSRRead8(addr + CR_IRQ_HANDLER_CAP));
203  errlogPrintf("IRQ Src Cap. : 0x%02x\n",CSRRead8(addr + CR_IRQ_CAP));
204  errlogPrintf("CRAM data width:0x%02x\n",CSRRead8(addr + CR_CRAM_WIDTH));
205  for(i=0;i<8;i++){
206  unsigned j;
207  size_t ader;
208  errlogPrintf("Function %d\n",i);
209  errlogPrintf(" Data width: %02x\n",CSRRead8(addr + CR_FN_DAWPR(i)));
210  errlogPrintf(" Data AM : ");
211  for(j=0;j<0x20;j+=4)
212  errlogPrintf("%02x",CSRRead8(addr + CR_FN_AMCAP(i) + j));
213  errlogPrintf("\n");
214  errlogPrintf(" Data XAM : ");
215  for(j=0;j<0x80;j+=4)
216  errlogPrintf("%02x",CSRRead8(addr + CR_FN_XAMCAP(i) + j));
217  errlogPrintf("\n");
218  errlogPrintf(" Data ADEM : ");
219  for(j=0;j<0x10;j+=4)
220  errlogPrintf("%02x",CSRRead8(addr + CR_FN_ADEM(i) + j));
221  errlogPrintf("\n");
222  ader=CSRRead32(addr + CSR_FN_ADER(i));
223  errlogPrintf(" Data ADER : Base %08x Mod %02x\n",
224  (unsigned int)ader&0xFfffFf00,(int)(ader&0xff)>>2);
225  }
226  }
227  }
228 
229  return;
230 }
231 
232 
233 void vmecsrdump(int v)
234 {
235  int i;
236  errlogFlush();
237 
238  errlogPrintf(">>> CSR/CR Dump\n");
239 
240  for(i=0;i<22;i++) {
241  vmecsrprint(i,v);
242  errlogFlush();
243  }
244 
245  errlogPrintf(">>> CSR/CR Dump End\n");
246  return;
247 }
#define CR_IEEE_OUI
IEEE Organizationally Unique Identifier (OUI)
Definition: devcsr.h:225
#define CR_ROM_CHECKSUM
8-bit checksum of Configuration ROM space
Definition: devcsr.h:216
#define CSR_BITSET_BERR
Module has asserted a Bus Error.
Definition: devcsr.h:317
#define CSR_BAR
Base Address Register (MSB of our CR/CSR address)
Definition: devcsr.h:296
#define devBusToLocalAddr
Definition: devLibVME.h:67
#define CSR_DATA_ACCESS_WIDTH
Control/Status Reg area (CSR) data access method.
Definition: devcsr.h:219
#define CR_FN_ADEM(N)
Start of Address Decoder Mask (ADEM) registers.
Definition: devcsr.h:275
epicsUInt32 vendor
Definition: devcsr.h:59
#define CR_BEG_SN
Offset to beginning of board serial number.
Definition: devcsr.h:246
#define CSRRead16(addr)
Definition: devcsr.h:144
#define CR_ROM_LENGTH
Number of bytes in Configuration ROM to checksum.
Definition: devcsr.h:217
#define CR_SLAVE_CHAR
Board&#39;s slave-mode characteristics.
Definition: devcsr.h:249
#define CR_ASCII_R
ASCII "R" (identifies this as CR space)
Definition: devcsr.h:223
#define CSR_UD_BIT_SET
User-Defined Bit Set Register (for user-defined fns)
Definition: devcsr.h:303
#define CR_ASCII_C
ASCII "C" (identifies this as CR space)
Definition: devcsr.h:222
#define CSRSlotBase(slot)
Derives the CSR space base address for a slot.
Definition: devcsr.h:130
#define VMECSRANY
Match any value. May be used in any field of VMECSRID.
Definition: devcsr.h:66
void vmecsrprint(int N, int v)
Decode contents of CSR/CR and print to screen.
Definition: devcsr.c:119
#define CSRRead24(addr)
Definition: devcsr.h:146
#define CSR_BITSET_CRAM_OWNED
CRAM is owned.
Definition: devcsr.h:318
#define CR_END_SN
Offset to end of board serial number.
Definition: devcsr.h:247
volatile unsigned char * devCSRTestSlot(const struct VMECSRID *devs, int slot, struct VMECSRID *info)
Probe a VME slot then check its ID.
Definition: devcsr.c:83
#define CR_IRQ_CAP
Interrupt levels board can assert.
Definition: devcsr.h:256
#define CR_END_UCSR
Offset to end of manufacturer-defined CSR space.
Definition: devcsr.h:244
#define CSR_BITSET_RESET_MODE
Module is in reset mode.
Definition: devcsr.h:313
ID info for a VME64(x) device This structure is used to hold identifying information for a VME64 comp...
Definition: devcsr.h:58
#define CR_SPACE_ID
CR/CSR space ID (VME64, VME64X, etc).
Definition: devcsr.h:220
#define CSR_BITSET_MODULE_ENA
Module is enabled.
Definition: devcsr.h:316
#define CR_DATA_ACCESS_WIDTH
Configuration ROM area (CR) data access method.
Definition: devcsr.h:218
#define CR_REVISION_ID
Manufacturer&#39;s board revision ID.
Definition: devcsr.h:229
volatile unsigned char * devCSRProbeSlot(int slot)
Get the CSR base address for a slot.
Definition: devcsr.c:18
#define VMECSRSLOTMAX
The highest slot number.
Definition: devcsr.h:69
#define CR_BEG_UCSR
Offset to start of manufacturer-defined CSR space.
Definition: devcsr.h:243
epicsUInt32 board
Definition: devcsr.h:59
#define atVMECSR
Definition: devLibVME.h:39
#define CR_CRAM_WIDTH
Configuration RAM (CRAM) data access method)
Definition: devcsr.h:258
#define CSRRead32(addr)
Definition: devcsr.h:148
#define CSR_BITSET_SYSFAIL_ENA
SYSFAIL driver is enabled.
Definition: devcsr.h:314
#define CSR_BITSET_MODULE_FAIL
Module has failed.
Definition: devcsr.h:315
#define CR_BOARD_ID
Manufacturer&#39;s board ID.
Definition: devcsr.h:227
#define CR_FN_DAWPR(N)
Start of Data Access Width Parameter (DAWPR) regs.
Definition: devcsr.h:260
#define CR_FN_XAMCAP(N)
Start of Extended Address Mode Cap (XAMCAP) registers.
Definition: devcsr.h:270
#define CSR_FN_ADER(N)
Function N Address Decoder Compare Register (1st byte)
Definition: devcsr.h:305
#define CR_BEG_UCR
Offset to start of manufacturer-defined CR space.
Definition: devcsr.h:236
#define CR_FN_AMCAP(N)
Start of Address Mode Capability (AMCAP) registers.
Definition: devcsr.h:265
#define CSRRead8(addr)
Definition: devcsr.h:142
void vmecsrdump(int v)
Decode contents of CSR/CR for all cards and print to screen.
Definition: devcsr.c:233
#define CSR_CRAM_OWNER
Configuration RAM Owner Register (0 = not owned)
Definition: devcsr.h:302
#define CR_MASTER_CHAR
Board&#39;s master-mode characteristics.
Definition: devcsr.h:252
#define CR_PROGRAM_ID
Program ID code for CR space.
Definition: devcsr.h:232
#define CSR_BIT_SET
Bit Set Register (writing a 1 sets the control bit)
Definition: devcsr.h:297
epicsUInt32 revision
Definition: devcsr.h:59
#define CR_IRQ_HANDLER_CAP
Interrupt levels board can respond to (handle)
Definition: devcsr.h:255
long devReadProbe(unsigned wordSize, volatile const void *ptr, void *pValueRead)
Definition: devlib_dummy.c:28
#define CR_END_UCR
Offset to end of manufacturer-defined CR space.
Definition: devcsr.h:237