1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * PCI Table Generator File: mkpcidb.c 5 * 6 * Author: Mitch Lichtenberg (mpl@broadcom.com) 7 * 8 * This program munges the PCI table into a form that uses 9 * fewer embedded pointers. Pointers are evil for the 10 * relocatable version of CFE since they chew up valuable 11 * initialized data segment space, and we only have 12 * 64KB of that. 13 * 14 ********************************************************************* 15 * 16 * Copyright 2000,2001,2002,2003 17 * Broadcom Corporation. All rights reserved. 18 * 19 * This software is furnished under license and may be used and 20 * copied only in accordance with the following terms and 21 * conditions. Subject to these conditions, you may download, 22 * copy, install, use, modify and distribute modified or unmodified 23 * copies of this software in source and/or binary form. No title 24 * or ownership is transferred hereby. 25 * 26 * 1) Any source code used, modified or distributed must reproduce 27 * and retain this copyright notice and list of conditions 28 * as they appear in the source file. 29 * 30 * 2) No right is granted to use any trade name, trademark, or 31 * logo of Broadcom Corporation. The "Broadcom Corporation" 32 * name may not be used to endorse or promote products derived 33 * from this software without the prior written permission of 34 * Broadcom Corporation. 35 * 36 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 37 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 38 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 39 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 40 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 41 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 44 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 45 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 46 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 47 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 48 * THE POSSIBILITY OF SUCH DAMAGE. 49 ********************************************************************* */ 50 51#include <stdio.h> 52#include <string.h> 53#include <unistd.h> 54 55typedef unsigned short pci_vendor_id_t; 56typedef unsigned short pci_product_id_t; 57 58struct pci_knowndev { 59 pci_vendor_id_t vendor; 60 pci_product_id_t product; 61 int flags; 62 char *vendorname, *productname; 63}; 64 65#include "../pci/pcidevs.h" 66#define PCI_KNOWNDEV_NOPROD 0x01 67#include "../pci/pcidevs_data.h" 68 69 70 71struct pci_knowndev2 { 72 pci_vendor_id_t vendor; 73 pci_product_id_t product; 74 int flags; 75 int vendorname; 76 int productname; 77}; 78 79#define MAXPCIDEVS 5000 80#define MAXSTRINGTABLE (1024*1024) 81 82struct pci_knowndev2 knowndevs[MAXPCIDEVS]; 83char stringtable[MAXSTRINGTABLE]; 84int curstringptr = 0; 85 86int allocstring(char *string) 87{ 88 int ptr; 89 90 if (!string) return -1; 91 92 ptr = curstringptr; 93 strcpy(&stringtable[ptr],string); 94 curstringptr += strlen(string)+1; 95 return ptr; 96} 97 98int main(int argc,char *argv[]) 99{ 100 struct pci_knowndev2 *outdev; 101 const struct pci_knowndev *indev; 102 int cnt = 0; 103 int idx; 104 105 indev = pci_knowndevs; 106 outdev = knowndevs; 107 cnt = 0; 108 109 while (indev->vendorname) { 110 outdev->vendor = indev->vendor; 111 outdev->product = indev->product; 112 outdev->flags = indev->flags; 113 outdev->vendorname = allocstring(indev->vendorname); 114 outdev->productname = allocstring(indev->productname); 115 cnt++; 116 indev++; 117 outdev++; 118 } 119 120 outdev->vendor = 0; 121 outdev->product = 0; 122 outdev->flags = 0; 123 outdev->vendorname = -1; 124 outdev->productname = -1; 125 cnt++; 126 127 fprintf(stderr,"%d total devices (%d bytes), %d bytes of strings\n", 128 cnt,cnt*sizeof(struct pci_knowndev2),curstringptr); 129 130 printf("\n\n\n"); 131 printf("const static struct pci_knowndev2 _pci_knowndevs[] __attribute__ ((section (\".text\"))) = {\n"); 132 for (idx = 0; idx < cnt; idx++) { 133 printf("\t{0x%04X,0x%04X,0x%08X,%d,%d},\n", 134 knowndevs[idx].vendor, 135 knowndevs[idx].product, 136 knowndevs[idx].flags, 137 knowndevs[idx].vendorname, 138 knowndevs[idx].productname); 139 } 140 printf("};\n\n\n"); 141 printf("const static char _pci_knowndevs_text[] __attribute__ ((section (\".text\"))) = {\n"); 142 for (idx = 0; idx < curstringptr; idx++) { 143 if ((idx % 16) == 0) printf("\t"); 144 printf("0x%02X,",stringtable[idx]); 145 if ((idx % 16) == 15) printf("\n"); 146 } 147 printf("0};\n\n"); 148 149 printf("static const struct pci_knowndev2 *pci_knowndevs = _pci_knowndevs;\n"); 150 printf("static const char *pci_knowndevs_text = _pci_knowndevs_text;\n"); 151 printf("#define PCI_STRING_NULL (-1)\n"); 152 printf("#define PCI_STRING(x) (&pci_knowndevs_text[(x)])\n\n"); 153 154 155 156 exit(0); 157} 158 159 160