2 * @file drmGeneration.c
4 * @brief Generates a specific PCI device Driver/Simulator code
6 * @author Copyright (C) 2002 CERN. Stuart Baird
7 * @author Copyright (C) 2003 CERN. Alain Gagnaire
8 * @author Copyright (C) 2003 - 2010 CERN. Georgievskiy Yury <ygeorgie@cern.ch>
10 * @date Created on 27/02/2004
12 * @section license_sec License
13 * Released under the GPL
15 #include "driverGen.h"
17 static void GenerateDrmInfo(PciInfo_t
*, BlockDef_t
*, int);
18 static void BuildDrmHeaderFile(int, RegisterDef_t
*, int, BlockDef_t
*, int);
19 static void BuildDrmStatics(BlockDef_t
*, int, FILE *, int);
20 static void BuildDrmDrvrFile(RegisterDef_t
*, int, BlockDef_t
*, int);
21 static void BuildDrmSimFile(RegisterDef_t
*, int, BlockDef_t
*, int);
24 * @brief Generates the entire driver source code from scratch, including
27 * @param registers - register description
28 * @param numRegisters - register amount
29 * @param blocks - block description
30 * @param numBlocks - block amount
31 * @param pciInfo - @e pci description
35 void GenerateDrmDriver(RegisterDef_t
* registers
, int numRegisters
,
36 BlockDef_t
* blocks
, int numBlocks
, PciInfo_t
* pciInfo
)
38 char *system
= TranslationGetSysLower();
40 /* First, build-up major source code of the driver */
41 GenerateDrmCore(registers
, numRegisters
, blocks
, numBlocks
, pciInfo
);
43 /* Now build-up user-defined driver files for the current module */
44 printf("Building %s user entry poins.\n", system
);
45 BuildUserPartDrvrCode();
49 * @brief Generates major source code of the driver, excluding the generation
50 * of user-defined files.
52 * @param registers - register description
53 * @param numRegisters - register amoun
54 * @param blocks - block description
55 * @param numBlocks - block amoun
56 * @param pciInfo - @e pci description
60 void GenerateDrmCore(RegisterDef_t
* registers
, int numRegisters
,
61 BlockDef_t
* blocks
, int numBlocks
, PciInfo_t
* pciInfo
)
63 char *system
= TranslationGetSysLower();
65 /*-=-=-=-=-=-=-=-=-=-=-=-=- 00. PCI driver. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
66 printf("Building %s driver's source code\n", system
);
67 /* Header file for driver. */
68 BuildDrmHeaderFile(DRIVER_FT
, registers
, numRegisters
, blocks
,
71 BuildDrmDrvrFile(registers
, numRegisters
, blocks
, numBlocks
);
73 /*-=-=-=-=-=-=-=-=-=-=-= 01. PCI simulator. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
74 printf("Building %s driver's simulator source code.\n", system
);
75 /* Header file for simulator. */
76 BuildDrmHeaderFile(SIM_FT
, registers
, numRegisters
, blocks
, numBlocks
);
77 /* Simulator source. */
78 BuildDrmSimFile(registers
, numRegisters
, blocks
, numBlocks
);
80 /*-=-=-=-=-=-=-=-=-02. Driver/Simulator registers r/w operations-=-=-=-=-=-*/
81 /* TODO. Take care of the third parameter! It's incorrect in this caseQ */
82 BuildGetSetRegCH(registers
, numRegisters
, NULL
);
84 /*--------------------03. Libraries---------------------------------------*/
85 printf("Building %s access library\n", system
);
86 BuildIoctlLibrary(registers
, numRegisters
, blocks
, numBlocks
);
89 printf("Building %s test program\n", system
);
90 BuildTestProgram(registers
, numRegisters
, blocks
, numBlocks
);
92 /*========XX. REGISTER DESCRIPTINON AND INFO FILE.========*/
93 GenerateDrmInstallFilesOLD(pciInfo
, blocks
, numBlocks
);
96 printf("Building %s makefile\n", system
);
101 * @brief SHOULD BE REMOVED.
103 * @param pciInfo - @e pci info
104 * @param blocks - block description
105 * @param numBlocks - block amount
109 void GenerateDrmInstallFilesOLD(PciInfo_t
* pciInfo
, BlockDef_t
* blocks
,
112 char *system
= TranslationGetModName();
114 printf("Building %s essential installation files:\n", system
);
115 printf(" Description files.\n");
117 printf(" Instance info structure.\n");
118 GenerateDrmInfo(pciInfo
, blocks
, numBlocks
);
122 * @brief Generate an info structure to be used by all drivers.
124 * @param pciInfo - @e pci info
125 * @param blocks - block description
126 * @param numBlocks - block amount
128 * As a PCI driver had no need of an info structure, a dummy one is used to
129 * satisfy the LynxOS driver format.
133 static void GenerateDrmInfo(PciInfo_t
* pciInfo
, BlockDef_t
* blocks
,
136 FILE *infoFile
= OpenFile(DRIVER_FT
, LOC_MODSRC
, "INST/.inst");
138 fwrite(pciInfo
, sizeof(pciInfo
), 1, infoFile
);
145 * @param type - driver or simulator
146 * @param registers - register description
147 * @param numRegisters - register amount
148 * @param blocks - block description
149 * @param numBlocks - block amoun
153 static void BuildDrmHeaderFile(int type
, RegisterDef_t
* registers
,
154 int numRegisters
, BlockDef_t
* blocks
,
160 headerFile
= OpenFile(type
, LOC_INCL
, ".h");
162 /* Generate the header file's head and then go to generate the rest */
163 Translate(headerFile
, "drm", "header/head.h");
164 /* Generate the constants used for the IOCTL function */
165 BuildIoctlConsts(registers
, numRegisters
, headerFile
);
167 TranslationSetPlainNum(numRegisters
* 2);
168 Translate(headerFile
, "drm", "header/configConst.h");
169 /* Generate the statics, info and block structures. */
170 BuildCommonBlocks(type
, registers
, numRegisters
, headerFile
);
171 BuildDrmStatics(blocks
, numBlocks
, headerFile
, type
);
179 * @param blocks - block description
180 * @param numBlocks - block amount
181 * @param headerFile - open file dscriptor
182 * @param type - driver or simulator
186 static void BuildDrmStatics(BlockDef_t
* blocks
, int numBlocks
,
187 FILE * headerFile
, int type
)
192 Translate(headerFile
, "drm", "header/topologyHead.h");
194 /* For each block that's been defined, place a field in the statics
195 structure. A PCI device may have a maximum of 6 blocks defined
196 so ignore any blocks out of the range 0-5. */
197 for (i
= 0; i
< numBlocks
; i
++) {
198 TranslationSetFancyNum(blocks
[i
].blockID
);
199 Translate(headerFile
, "common", "header/blockDef.h");
202 /* Close the statics structure and generate the info one. */
203 TranslationSetDriverType((type
== DRIVER_FT
) ? "DRVR" : "SIM");
204 Translate(headerFile
, "common", "header/topologyFoot.h");
208 * @brief Generate the driver's source file.
210 * @param registers - register description
211 * @param numRegisters - register amount
212 * @param blocks - block description
213 * @param numBlocks - block amount
217 static void BuildDrmDrvrFile(RegisterDef_t
* registers
, int numRegisters
,
218 BlockDef_t
* blocks
, int numBlocks
)
220 FILE *dfd
= OpenFile(DRIVER_FT
, LOC_DRVR
, ".c");
224 Translate(dfd
, "drm", "driver/head.c");
226 TranslationSetDriverType("Drvr");
227 TranslationSetFancyString("DRVR");
228 TranslationSetDummyString("Driver");
229 Translate(dfd
, "common", "driver/driverHead.c");
231 /* Generate driver's open routine */
232 Translate(dfd
, "drm", "driver/open/drvrOpen.c");
234 /* Generate driver's close routine. */
235 Translate(dfd
, "common", "driver/close/head.c");
237 /* Generate driver's read routine. */
238 Translate(dfd
, "common", "driver/read/head.c");
240 /* Generate driver's write routine. */
241 Translate(dfd
, "common", "driver/write/head.c");
243 /* Generate driver's select routine. */
244 Translate(dfd
, "common", "driver/select/head.c");
246 /* Generate driver's ioctl routine. */
247 BuildDrvrSimIoctl(registers
, numRegisters
, dfd
);
249 /* Generate driver's install routine. */
250 Translate(dfd
, "drm", "driver/install/installHead.c");
251 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
252 TranslationSetPlainNum(blocks
[cntr
].blockID
);
253 TranslationSetFancyNum(blocks
[cntr
].blockID
);
254 Translate(dfd
, "drm", "driver/install/installBlock.c");
256 Translate(dfd
, "drm", "driver/install/installFoot.c");
258 /* Generate driver's uninstall routine. */
259 Translate(dfd
, "drm", "driver/uninstall/uninstallHead.c");
260 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
261 TranslationSetPlainNum(blocks
[cntr
].blockID
);
262 Translate(dfd
, "drm", "driver/uninstall/uninstallBlock.c");
264 Translate(dfd
, "drm", "driver/uninstall/uninstallFoot.c");
266 /* Generate an empty ISR */
267 Translate(dfd
, "common", "driver/isr.c");
269 /* Build-up dldd structure (driver entry points) */
270 TranslationSetDriverType("Drvr");
271 Translate(dfd
, "common", "driver/entryPoints.c");
277 * @brief Generate the simulator's source file.
279 * @param registers - register description
280 * @param numRegisters - register amount
281 * @param blocks - block description
282 * @param numBlocks - block amount
286 static void BuildDrmSimFile(RegisterDef_t
* registers
, int numRegisters
,
287 BlockDef_t
* blocks
, int numBlocks
)
289 FILE *sfd
= OpenFile(SIM_FT
, LOC_DRVR
, ".c");
293 Translate(sfd
, "drm", "driver/head.c");
295 TranslationSetDriverType("Sim");
296 TranslationSetFancyString("SIM");
297 TranslationSetDummyString("Simulator");
298 Translate(sfd
, "common", "driver/driverHead.c");
300 /* Generate simulator's open routine. */
301 Translate(sfd
, "drm", "driver/open/simOpenHead.c");
302 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
303 TranslationSetFancyNum(blocks
[cntr
].blockID
);
304 TranslationSetPlainNum(blocks
[cntr
].blockID
);
305 Translate(sfd
, "common", "driver/install/allocateBlock.c");
307 Translate(sfd
, "drm", "driver/open/installConfig.c");
308 Translate(sfd
, "drm", "driver/open/simOpenFoot.c");
310 /* Generate simulator's close routine. */
311 Translate(sfd
, "common", "driver/close/head.c");
313 /* Generate simulator's read routine. */
314 Translate(sfd
, "common", "driver/read/head.c");
316 /* Generate simulator's write routine. */
317 Translate(sfd
, "common", "driver/write/head.c");
319 /* Generate simulator's select routine. */
320 Translate(sfd
, "common", "driver/select/head.c");
322 /* Generate simulator's ioctl routine. */
323 BuildDrvrSimIoctl(registers
, numRegisters
, sfd
);
325 /* Generate simulator's install routine. */
326 Translate(sfd
, "drm", "driver/install/simInstall.c");
328 /* Generate simulator's uninstall routine. */
329 Translate(sfd
, "drm", "driver/uninstall/simUninstallHead.c");
330 for (cntr
= 0; cntr
< numBlocks
; cntr
++) {
331 TranslationSetFancyNum(blocks
[cntr
].blockID
);
332 TranslationSetPlainNum(blocks
[cntr
].blockID
);
333 Translate(sfd
, "common", "driver/uninstall/uninstallBlocks.c");
335 Translate(sfd
, "common", "driver/uninstall/foot.c");
337 /* Generate an empty ISR */
338 Translate(sfd
, "common", "driver/isr.c");
340 /* Build-up dldd structure (simulator entry points) */
341 TranslationSetDriverType("Sim");
342 Translate(sfd
, "common", "driver/entryPoints.c");