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 53 static struct modlmisc modlmisc = { 54 &mod_miscops, "PCI BIOS interface" 55 }; 56 57 static struct modlinkage modlinkage = { 58 MODREV_1, (void *)&modlmisc, NULL 59 }; 60 61 int 62 _init(void) 63 { 64 int err; 65 66 if ((err = mod_install(&modlinkage)) != 0) 67 return (err); 68 69 impl_bus_add_probe(pci_enumerate); 70 return (0); 71 } 72 73 int 74 _fini(void) 75 { 76 int err; 77 78 if ((err = mod_remove(&modlinkage)) != 0) 79 return (err); 80 81 impl_bus_delete_probe(pci_enumerate); 82 return (0); 83 } 84 85 int 86 _info(struct modinfo *modinfop) 87 { 88 return (mod_info(&modlinkage, modinfop)); 89 } 90 91 92 /* 93 * This function is invoked twice: first time, with reprogram=0 to 94 * set up the PCI portion of the device tree. The second time is 95 * for reprogramming devices not set up by the BIOS. 96 */ 97 void 98 pci_enumerate(int reprogram) 99 { 100 extern void add_pci_fixes(void); 101 extern void undo_pci_fixes(void); 102 103 add_pci_fixes(); 104 105 if (reprogram) { 106 pci_reprogram(); 107 undo_pci_fixes(); 108 return; 109 } 110 111 /* setup device tree */ 112 pci_setup_tree(); 113 undo_pci_fixes(); 114 } 115