]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/sysinstall/uc_pci.c
This commit was generated by cvs2svn to compensate for changes in r27180,
[FreeBSD/FreeBSD.git] / release / sysinstall / uc_pci.c
1 /***************************************************
2  * file: userconfig/uc_pci.c
3  *
4  * Copyright (c) 1996 Eric L. Hernes (erich@rrnet.com)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. The name of the author may not be used to endorse or promote products
13  *    derived from this software withough specific prior written permission
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $Id$
27  */
28
29 #include <sys/types.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <nlist.h>
34 #include <pci/pcivar.h>
35
36 #include "uc_main.h"
37
38 void
39 get_pci_info(struct kernel *kp){
40   int i, total;
41   u_int *ls, ndev;
42   struct pci_device *pd;
43   struct uc_pci *pp,*ppc;
44   char *name;
45
46   if(kp->nl[PCI_SET].n_value){
47     pp = ppc = (struct uc_pci *)malloc(sizeof(struct uc_pci));
48     ls=(u_int *)kv_to_u(kp, kp->nl[PCI_SET].n_value, sizeof(u_int)*30); /* XXX, size? */
49     ndev=ls[0];
50     total=0;
51     for(i=1;i<(ndev+1);i++){
52       pp=(struct uc_pci *)realloc(pp, sizeof(struct uc_pci)*(total+1));
53       ppc = pp+(total);
54       pd=(struct pci_device *)kv_to_u(kp, ls[i], sizeof(struct pci_device));
55       /* don't try to dereference a null pointer */
56       name=pd->pd_name ? (char *)kv_to_u(kp, (u_int)pd->pd_name, 10) :
57         pd->pd_name; /* XXX, size? */
58       if(kp->incore){
59         int u, k;
60         /* incore, we can get unit numbers */
61
62         u=kv_dref_p(kp, (u_int)pd->pd_count);
63         for(k=0;k<u;k++,total++){
64           pp=(struct uc_pci *)realloc(pp, sizeof(struct uc_pci)*(total+1));
65           ppc = pp+(total);
66           asprintf(&ppc->device, "%s%d", name, k);
67         }
68         free(pd);
69         if(name)
70           free(name);
71       } else {
72         asprintf(&ppc->device, "%s?", name);
73         total++;
74       }
75     }
76     pp=(struct uc_pci *)realloc(pp, sizeof(struct uc_pci)*(total+1));
77     ppc = pp+(total);
78     bzero(ppc, sizeof(struct uc_pci));
79     kp->pci_devp=pp;
80   } else {
81     kp->pci_devp=(struct uc_pci *)0;
82   }
83 }
84
85
86 struct list *
87 get_pci_devlist(struct kernel *kp){
88   struct list *dl;
89   struct uc_pci *kdp;
90
91   dl=list_new();
92
93   for(kdp=kp->pci_devp; kdp->device; kdp++){
94     list_append(dl, kdp->device);
95   }
96   return(dl);
97 }
98
99
100 struct list *
101 get_pci_device(struct uc_pci *pp){
102   struct list *list;
103   list=list_new();
104
105   list_append(list, pp->device);
106
107   return(list);
108 }
109
110 void
111 pci_free(struct kernel *kp, int writeback){
112   struct uc_pci *pp;
113
114   for(pp=kp->pci_devp;pp->device;pp++){
115     free(pp->device);
116   }
117   free(kp->pci_devp);
118   kp->pci_devp=0;
119   
120 }
121
122 /* end of userconfig/uc_pci.c */