Merge commit '5e2cca1843c61ee0ef1bb95c5dddc9b450b790c6'
[unleashed.git] / arch / x86 / kernel / os / pci_mech2.c
blob90f76199316c127d637b8571190e4f7543856d92
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * PCI Mechanism 2 primitives
33 #include <sys/types.h>
34 #include <sys/sunddi.h>
35 #include <sys/pci_impl.h>
36 #include <sys/pci_cfgspace_impl.h>
39 * The "mechanism 2" interface only has 4 bits for device number. To
40 * hide this implementation detail, we return all ones for accesses to
41 * devices 16..31.
43 #define PCI_MAX_DEVS_2 16
46 * the PCI LOCAL BUS SPECIFICATION 2.0 does not say that you need to
47 * save the value of the register and restore them. The Intel chip
48 * set documentation indicates that you should.
50 static uint8_t
51 pci_mech2_config_enable(uchar_t bus, uchar_t function)
53 uint8_t old;
55 mutex_enter(&pcicfg_mutex);
56 old = inb(PCI_CSE_PORT);
58 outb(PCI_CSE_PORT,
59 PCI_MECH2_CONFIG_ENABLE | ((function & PCI_FUNC_MASK) << 1));
60 outb(PCI_FORW_PORT, bus);
62 return (old);
65 static void
66 pci_mech2_config_restore(uint8_t oldstatus)
68 outb(PCI_CSE_PORT, oldstatus);
69 mutex_exit(&pcicfg_mutex);
72 uint8_t
73 pci_mech2_getb(int bus, int device, int function, int reg)
75 uint8_t tmp;
76 uint8_t val;
78 if (device >= PCI_MAX_DEVS_2)
79 return (0xff);
81 tmp = pci_mech2_config_enable(bus, function);
82 val = inb(PCI_CADDR2(device, reg));
83 pci_mech2_config_restore(tmp);
85 return (val);
88 uint16_t
89 pci_mech2_getw(int bus, int device, int function, int reg)
91 uint8_t tmp;
92 uint16_t val;
94 if (device >= PCI_MAX_DEVS_2)
95 return (0xffff);
97 tmp = pci_mech2_config_enable(bus, function);
98 val = inw(PCI_CADDR2(device, reg));
99 pci_mech2_config_restore(tmp);
101 return (val);
104 uint32_t
105 pci_mech2_getl(int bus, int device, int function, int reg)
107 uint8_t tmp;
108 uint32_t val;
110 if (device >= PCI_MAX_DEVS_2)
111 return (0xffffffffu);
113 tmp = pci_mech2_config_enable(bus, function);
114 val = inl(PCI_CADDR2(device, reg));
115 pci_mech2_config_restore(tmp);
117 return (val);
120 void
121 pci_mech2_putb(int bus, int device, int function, int reg, uint8_t val)
123 uint8_t tmp;
125 if (device >= PCI_MAX_DEVS_2)
126 return;
128 tmp = pci_mech2_config_enable(bus, function);
129 outb(PCI_CADDR2(device, reg), val);
130 pci_mech2_config_restore(tmp);
133 void
134 pci_mech2_putw(int bus, int device, int function, int reg, uint16_t val)
136 uint8_t tmp;
138 if (device >= PCI_MAX_DEVS_2)
139 return;
141 tmp = pci_mech2_config_enable(bus, function);
142 outw(PCI_CADDR2(device, reg), val);
143 pci_mech2_config_restore(tmp);
146 void
147 pci_mech2_putl(int bus, int device, int function, int reg, uint32_t val)
149 uint8_t tmp;
151 if (device >= PCI_MAX_DEVS_2)
152 return;
154 tmp = pci_mech2_config_enable(bus, function);
155 outl(PCI_CADDR2(device, reg), val);
156 pci_mech2_config_restore(tmp);