[driver-gen-git] Add git library files.
[driver-gen.git] / drmGeneration.c
blob93ce4c3965e1df0fc9fc8ee97a850ef206310471
1 /**
2 * @file drmGeneration.c
4 * @brief Generates a specific PCI device Driver/Simulator code
6 * @author Copyright (c) 2004 - 2009 CERN. Georgievskiy Yury, Alain Gagnaire
8 * @date Created on 27/02/2004
9 */
10 #include "driverGen.h"
12 /*================Static functions declaration===============================*/
13 static void GenerateDrmInfo(PciInfo_t *, BlockDef_t *, int);
14 static void BuildDrmHeaderFile(int, RegisterDef_t *, int, BlockDef_t *, int);
15 static void BuildDrmStatics(BlockDef_t *, int, FILE *, int);
16 static void BuildDrmDrvrFile(RegisterDef_t *, int, BlockDef_t *, int);
17 static void BuildDrmSimFile(RegisterDef_t *, int, BlockDef_t *, int);
18 /*=====================END of static function declaration====================*/
20 /**
21 * @brief Generates the entire driver source code from scratch, including
22 * user-defined files.
24 * @param registers - register description
25 * @param numRegisters - register amount
26 * @param blocks - block description
27 * @param numBlocks - block amount
28 * @param pciInfo - @e pci description
30 * @return void
32 void GenerateDrmDriver(RegisterDef_t * registers, int numRegisters,
33 BlockDef_t * blocks, int numBlocks, PciInfo_t * pciInfo)
35 char *system = TranslationGetSysLower();
37 /* First, build-up major source code of the driver */
38 GenerateDrmCore(registers, numRegisters, blocks, numBlocks, pciInfo);
40 /* Now build-up user-defined driver files for the current module */
41 printf("Building %s user entry poins.\n", system);
42 BuildUserPartDrvrCode();
45 /**
46 * @brief Generates major source code of the driver, excluding the generation
47 * of user-defined files.
49 * @param registers - register description
50 * @param numRegisters - register amoun
51 * @param blocks - block description
52 * @param numBlocks - block amoun
53 * @param pciInfo - @e pci description
55 * @return void
57 void GenerateDrmCore(RegisterDef_t * registers, int numRegisters,
58 BlockDef_t * blocks, int numBlocks, PciInfo_t * pciInfo)
60 char *system = TranslationGetSysLower();
62 /*-=-=-=-=-=-=-=-=-=-=-=-=- 00. PCI driver. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
63 printf("Building %s driver's source code\n", system);
64 /* Header file for driver. */
65 BuildDrmHeaderFile(DRIVER_FT, registers, numRegisters, blocks,
66 numBlocks);
67 /* Driver source. */
68 BuildDrmDrvrFile(registers, numRegisters, blocks, numBlocks);
70 /*-=-=-=-=-=-=-=-=-=-=-= 01. PCI simulator. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
71 printf("Building %s driver's simulator source code.\n", system);
72 /* Header file for simulator. */
73 BuildDrmHeaderFile(SIM_FT, registers, numRegisters, blocks, numBlocks);
74 /* Simulator source. */
75 BuildDrmSimFile(registers, numRegisters, blocks, numBlocks);
77 /*-=-=-=-=-=-=-=-=-02. Driver/Simulator registers r/w operations-=-=-=-=-=-*/
78 /* TODO. Take care of the third parameter! It's incorrect in this caseQ */
79 BuildGetSetRegCH(registers, numRegisters, NULL);
81 /*--------------------03. Libraries---------------------------------------*/
82 printf("Building %s access library\n", system);
83 BuildIoctlLibrary(registers, numRegisters, blocks, numBlocks);
85 /* */
86 printf("Building %s test program\n", system);
87 BuildTestProgram(registers, numRegisters, blocks, numBlocks);
89 /*========XX. REGISTER DESCRIPTINON AND INFO FILE.========*/
90 GenerateDrmInstallFilesOLD(pciInfo, blocks, numBlocks);
92 /* */
93 printf("Building %s makefile\n", system);
94 BuildMakefiles();
97 /**
98 * @brief SHOULD BE REMOVED.
100 * @param pciInfo - @e pci info
101 * @param blocks - block description
102 * @param numBlocks - block amount
104 * @return void
106 void GenerateDrmInstallFilesOLD(PciInfo_t * pciInfo, BlockDef_t * blocks,
107 int numBlocks)
109 char *system = TranslationGetModName();
111 printf("Building %s essential installation files:\n", system);
112 printf(" Description files.\n");
113 BuildDescsOLD(8);
114 printf(" Instance info structure.\n");
115 GenerateDrmInfo(pciInfo, blocks, numBlocks);
119 * @brief Generate an info structure to be used by all drivers.
121 * @param pciInfo - @e pci info
122 * @param blocks - block description
123 * @param numBlocks - block amount
125 * As a PCI driver had no need of an info structure, a dummy one is used to
126 * satisfy the LynxOS driver format.
128 * @return void
130 static void GenerateDrmInfo(PciInfo_t * pciInfo, BlockDef_t * blocks,
131 int numBlocks)
133 FILE *infoFile = OpenFile(DRIVER_FT, LOC_MODSRC, "INST/.inst");
135 fwrite(pciInfo, sizeof(pciInfo), 1, infoFile);
136 fclose(infoFile);
140 * @brief
142 * @param type - driver or simulator
143 * @param registers - register description
144 * @param numRegisters - register amount
145 * @param blocks - block description
146 * @param numBlocks - block amoun
148 * @return void
150 static void BuildDrmHeaderFile(int type, RegisterDef_t * registers,
151 int numRegisters, BlockDef_t * blocks,
152 int numBlocks)
154 FILE *headerFile;
156 TranslationReset();
157 headerFile = OpenFile(type, LOC_INCL, ".h");
159 /* Generate the header file's head and then go to generate the rest */
160 Translate(headerFile, "drm", "header/head.h");
161 /* Generate the constants used for the IOCTL function */
162 BuildIoctlConsts(registers, numRegisters, headerFile);
164 TranslationSetPlainNum(numRegisters * 2);
165 Translate(headerFile, "drm", "header/configConst.h");
166 /* Generate the statics, info and block structures. */
167 BuildCommonBlocks(type, registers, numRegisters, headerFile);
168 BuildDrmStatics(blocks, numBlocks, headerFile, type);
170 fclose(headerFile);
174 * @brief
176 * @param blocks - block description
177 * @param numBlocks - block amount
178 * @param headerFile - open file dscriptor
179 * @param type - driver or simulator
181 * @return void
183 static void BuildDrmStatics(BlockDef_t * blocks, int numBlocks,
184 FILE * headerFile, int type)
186 int i;
188 TranslationReset();
189 Translate(headerFile, "drm", "header/topologyHead.h");
191 /* For each block that's been defined, place a field in the statics
192 structure. A PCI device may have a maximum of 6 blocks defined
193 so ignore any blocks out of the range 0-5. */
194 for (i = 0; i < numBlocks; i++) {
195 TranslationSetFancyNum(blocks[i].blockID);
196 Translate(headerFile, "common", "header/blockDef.h");
199 /* Close the statics structure and generate the info one. */
200 TranslationSetDriverType((type == DRIVER_FT) ? "DRVR" : "SIM");
201 Translate(headerFile, "common", "header/topologyFoot.h");
205 * @brief Generate the driver's source file.
207 * @param registers - register description
208 * @param numRegisters - register amount
209 * @param blocks - block description
210 * @param numBlocks - block amount
212 * @return void
214 static void BuildDrmDrvrFile(RegisterDef_t * registers, int numRegisters,
215 BlockDef_t * blocks, int numBlocks)
217 FILE *dfd = OpenFile(DRIVER_FT, LOC_DRVR, ".c");
218 int cntr;
220 TranslationReset();
221 Translate(dfd, "drm", "driver/head.c");
223 TranslationSetDriverType("Drvr");
224 TranslationSetFancyString("DRVR");
225 TranslationSetDummyString("Driver");
226 Translate(dfd, "common", "driver/driverHead.c");
228 /* Generate driver's open routine */
229 Translate(dfd, "drm", "driver/open/drvrOpen.c");
231 /* Generate driver's close routine. */
232 Translate(dfd, "common", "driver/close/head.c");
234 /* Generate driver's read routine. */
235 Translate(dfd, "common", "driver/read/head.c");
237 /* Generate driver's write routine. */
238 Translate(dfd, "common", "driver/write/head.c");
240 /* Generate driver's select routine. */
241 Translate(dfd, "common", "driver/select/head.c");
243 /* Generate driver's ioctl routine. */
244 BuildDrvrSimIoctl(registers, numRegisters, dfd);
246 /* Generate driver's install routine. */
247 Translate(dfd, "drm", "driver/install/installHead.c");
248 for (cntr = 0; cntr < numBlocks; cntr++) {
249 TranslationSetPlainNum(blocks[cntr].blockID);
250 TranslationSetFancyNum(blocks[cntr].blockID);
251 Translate(dfd, "drm", "driver/install/installBlock.c");
253 Translate(dfd, "drm", "driver/install/installFoot.c");
255 /* Generate driver's uninstall routine. */
256 Translate(dfd, "drm", "driver/uninstall/uninstallHead.c");
257 for (cntr = 0; cntr < numBlocks; cntr++) {
258 TranslationSetPlainNum(blocks[cntr].blockID);
259 Translate(dfd, "drm", "driver/uninstall/uninstallBlock.c");
261 Translate(dfd, "drm", "driver/uninstall/uninstallFoot.c");
263 /* Generate an empty ISR */
264 Translate(dfd, "common", "driver/isr.c");
266 /* Build-up dldd structure (driver entry points) */
267 TranslationSetDriverType("Drvr");
268 Translate(dfd, "common", "driver/entryPoints.c");
270 fclose(dfd);
274 * @brief Generate the simulator's source file.
276 * @param registers - register description
277 * @param numRegisters - register amount
278 * @param blocks - block description
279 * @param numBlocks - block amount
281 * @return void
283 static void BuildDrmSimFile(RegisterDef_t * registers, int numRegisters,
284 BlockDef_t * blocks, int numBlocks)
286 FILE *sfd = OpenFile(SIM_FT, LOC_DRVR, ".c");
287 int cntr;
289 TranslationReset();
290 Translate(sfd, "drm", "driver/head.c");
292 TranslationSetDriverType("Sim");
293 TranslationSetFancyString("SIM");
294 TranslationSetDummyString("Simulator");
295 Translate(sfd, "common", "driver/driverHead.c");
297 /* Generate simulator's open routine. */
298 Translate(sfd, "drm", "driver/open/simOpenHead.c");
299 for (cntr = 0; cntr < numBlocks; cntr++) {
300 TranslationSetFancyNum(blocks[cntr].blockID);
301 TranslationSetPlainNum(blocks[cntr].blockID);
302 Translate(sfd, "common", "driver/install/allocateBlock.c");
304 Translate(sfd, "drm", "driver/open/installConfig.c");
305 Translate(sfd, "drm", "driver/open/simOpenFoot.c");
307 /* Generate simulator's close routine. */
308 Translate(sfd, "common", "driver/close/head.c");
310 /* Generate simulator's read routine. */
311 Translate(sfd, "common", "driver/read/head.c");
313 /* Generate simulator's write routine. */
314 Translate(sfd, "common", "driver/write/head.c");
316 /* Generate simulator's select routine. */
317 Translate(sfd, "common", "driver/select/head.c");
319 /* Generate simulator's ioctl routine. */
320 BuildDrvrSimIoctl(registers, numRegisters, sfd);
322 /* Generate simulator's install routine. */
323 Translate(sfd, "drm", "driver/install/simInstall.c");
325 /* Generate simulator's uninstall routine. */
326 Translate(sfd, "drm", "driver/uninstall/simUninstallHead.c");
327 for (cntr = 0; cntr < numBlocks; cntr++) {
328 TranslationSetFancyNum(blocks[cntr].blockID);
329 TranslationSetPlainNum(blocks[cntr].blockID);
330 Translate(sfd, "common", "driver/uninstall/uninstallBlocks.c");
332 Translate(sfd, "common", "driver/uninstall/foot.c");
334 /* Generate an empty ISR */
335 Translate(sfd, "common", "driver/isr.c");
337 /* Build-up dldd structure (simulator entry points) */
338 TranslationSetDriverType("Sim");
339 Translate(sfd, "common", "driver/entryPoints.c");
341 fclose(sfd);