xref: /titanic_51/usr/src/uts/intel/io/pci/pci_autoconfig.c (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Determine the PCI configuration mechanism recommended by the BIOS.
28  */
29 
30 #include <sys/types.h>
31 #include <sys/sunddi.h>
32 #include <sys/pci_impl.h>
33 #include <sys/ddi_subrdefs.h>
34 #include <sys/bootconf.h>
35 #include <sys/psw.h>
36 #include <sys/modctl.h>
37 #include <sys/errno.h>
38 #include <sys/pci.h>
39 #include <sys/pci_cfgspace.h>
40 #include <sys/reboot.h>
41 #include <sys/pci_cfgspace_impl.h>
42 #include <sys/mutex.h>
43 
44 extern int pci_boot_debug;
45 
46 /*
47  * Interface routines
48  */
49 void pci_enumerate(int);
50 void pci_setup_tree(void);
51 void pci_reprogram(void);
52 void bus_res_fini(void);
53 
54 static struct modlmisc modlmisc = {
55 	&mod_miscops, "PCI BIOS interface"
56 };
57 
58 static struct modlinkage modlinkage = {
59 	MODREV_1, (void *)&modlmisc, NULL
60 };
61 
62 int
63 _init(void)
64 {
65 	int	err;
66 
67 	if ((err = mod_install(&modlinkage)) != 0)
68 		return (err);
69 
70 	impl_bus_add_probe(pci_enumerate);
71 	return (0);
72 }
73 
74 int
75 _fini(void)
76 {
77 	int	err;
78 
79 	if ((err = mod_remove(&modlinkage)) != 0)
80 		return (err);
81 
82 	impl_bus_delete_probe(pci_enumerate);
83 	bus_res_fini();
84 	return (0);
85 }
86 
87 int
88 _info(struct modinfo *modinfop)
89 {
90 	return (mod_info(&modlinkage, modinfop));
91 }
92 
93 
94 /*
95  * This function is invoked twice: first time, with reprogram=0 to
96  * set up the PCI portion of the device tree. The second time is
97  * for reprogramming devices not set up by the BIOS.
98  */
99 void
100 pci_enumerate(int reprogram)
101 {
102 	extern void add_pci_fixes(void);
103 	extern void undo_pci_fixes(void);
104 
105 	add_pci_fixes();
106 
107 	if (reprogram) {
108 		pci_reprogram();
109 		undo_pci_fixes();
110 		return;
111 	}
112 
113 	/* setup device tree */
114 	pci_setup_tree();
115 	undo_pci_fixes();
116 }
117