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 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 /* 29 * Determine the PCI configuration mechanism recommended by the BIOS. 30 */ 31 32 #include <sys/types.h> 33 #include <sys/sunddi.h> 34 #include <sys/pci_impl.h> 35 #include <sys/ddi_subrdefs.h> 36 #include <sys/bootconf.h> 37 #include <sys/psw.h> 38 #include <sys/modctl.h> 39 #include <sys/errno.h> 40 #include <sys/pci.h> 41 #include <sys/pci_cfgspace.h> 42 #include <sys/reboot.h> 43 #include <sys/pci_cfgspace_impl.h> 44 #include <sys/mutex.h> 45 46 extern int pci_boot_debug; 47 48 /* 49 * Interface routines 50 */ 51 void pci_enumerate(int); 52 void pci_setup_tree(void); 53 void pci_reprogram(void); 54 55 static struct modlmisc modlmisc = { 56 &mod_miscops, "PCI BIOS interface %I%" 57 }; 58 59 static struct modlinkage modlinkage = { 60 MODREV_1, (void *)&modlmisc, NULL 61 }; 62 63 int 64 _init(void) 65 { 66 int err; 67 68 if ((err = mod_install(&modlinkage)) != 0) 69 return (err); 70 71 impl_bus_add_probe(pci_enumerate); 72 return (0); 73 } 74 75 int 76 _fini(void) 77 { 78 int err; 79 80 if ((err = mod_remove(&modlinkage)) != 0) 81 return (err); 82 83 impl_bus_delete_probe(pci_enumerate); 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