/* * Copyright (C) 2006, Intel Corporation * * This file is part of the Linux-ready Firmware Developer Kit * * This program file is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation;version 2.1 of the License. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program in a file named COPYING; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "../biostest.h" /* Run 'lspci -vxxx' and parse it so we can announce each PCI device and its information as a resource (i.e. in the resource list) */ void gather_pci_info(void) { FILE *file; char line[4096]; char pciuri[1024]; char *thisfield = strdup(""); char *lspci_cmd; int config = 0; memset(pciuri, 0, 1024); lspci_cmd = get_relative_command ("lspci", " -vxxx"); if(!lspci_cmd) { sprintf(line,"echo lspci not found >> %s", LFDK_ERRLOG); system(line); return; } file = popen(lspci_cmd, "r"); if (!file) return; while (!feof(file)) { int skipwhite = 0; memset(line, 0, 4096); if (fgets(line, 4095, file)==NULL) break; if (strlen(line)<2) { /* end of device */ announce_resource(pciuri, thisfield, NULL); free(thisfield); thisfield=strdup(""); config=0; } else { char *c; c = line; if (strlen(thisfield)<1 && strlen(line)>8) { char *c2; c[7]=0; c+=8; sprintf(pciuri,"pci://0000:%s",line); c2 = strchr(c,':'); if (c2) { *c2=0; thisfield = scatprintf(thisfield,"%s\n",c); c=c2+1; } skipwhite = 1; } while (*c==' ') { c++; skipwhite=1;}; while (*c=='\t') { c++; skipwhite=1;}; if (!config && !skipwhite) { thisfield = scatprintf(thisfield,"\nPCI config space:\n"); config=1; } thisfield = scatprintf(thisfield, "%s", c); } } /* Announcing the PCI device as a resource pci://0000: then the information and values from lspci -vxxx */ if (strlen(thisfield)>2) announce_resource(pciuri, thisfield, NULL); }