8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / uts / i86pc / os / pci_mech1_amd.c
blob3b6eb918fe1f6306f489b3ffcd9882ca6eb00f8e
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Advanced Micro Devices, Inc.
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
27 * PCI Mechanism 1 low-level routines with ECS support for AMD family >= 0x10
30 #include <sys/controlregs.h>
31 #include <sys/cpuvar.h>
32 #include <sys/types.h>
33 #include <sys/pci.h>
34 #include <sys/pci_impl.h>
35 #include <sys/sunddi.h>
36 #include <sys/pci_cfgspace_impl.h>
37 #include <sys/x86_archext.h>
39 boolean_t
40 pci_check_amd_ioecs(void)
42 struct cpuid_regs cp;
43 int family;
45 if (!is_x86_feature(x86_featureset, X86FSET_CPUID))
46 return (B_FALSE);
49 * Get the CPU vendor string from CPUID.
50 * This PCI mechanism only applies to AMD CPUs.
52 cp.cp_eax = 0;
53 (void) __cpuid_insn(&cp);
55 if ((cp.cp_ebx != 0x68747541) || /* Auth */
56 (cp.cp_edx != 0x69746e65) || /* enti */
57 (cp.cp_ecx != 0x444d4163)) /* cAMD */
58 return (B_FALSE);
61 * Get the CPU family from CPUID.
62 * This PCI mechanism is only available on family 0x10 or higher.
64 cp.cp_eax = 1;
65 (void) __cpuid_insn(&cp);
66 family = ((cp.cp_eax >> 8) & 0xf) + ((cp.cp_eax >> 20) & 0xff);
68 if (family < 0x10)
69 return (B_FALSE);
72 * Set the EnableCf8ExtCfg bit in the Northbridge Configuration Register
73 * to enable accessing PCI ECS using in/out instructions.
75 wrmsr(MSR_AMD_NB_CFG, rdmsr(MSR_AMD_NB_CFG) | AMD_GH_NB_CFG_EN_ECS);
76 return (B_TRUE);
80 * Macro to setup PCI Extended Configuration Space (ECS) address to give to
81 * "in/out" instructions
83 #define PCI_CADDR1_ECS(b, d, f, r) \
84 (PCI_CADDR1((b), (d), (f), (r)) | ((((r) >> 8) & 0xf) << 24))
87 * Per PCI 2.1 section 3.7.4.1 and PCI-PCI Bridge Architecture 1.0 section
88 * 5.3.1.2: dev=31 func=7 reg=0 means a special cycle. We don't want to
89 * trigger that by accident, so we pretend that dev 31, func 7 doesn't
90 * exist. If we ever want special cycle support, we'll add explicit
91 * special cycle support.
94 uint8_t
95 pci_mech1_amd_getb(int bus, int device, int function, int reg)
97 uint8_t val;
99 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
100 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
101 return (0xff);
104 mutex_enter(&pcicfg_mutex);
105 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
106 val = inb(PCI_CONFDATA | (reg & 0x3));
107 mutex_exit(&pcicfg_mutex);
108 return (val);
111 uint16_t
112 pci_mech1_amd_getw(int bus, int device, int function, int reg)
114 uint16_t val;
116 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
117 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
118 return (0xffff);
121 mutex_enter(&pcicfg_mutex);
122 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
123 val = inw(PCI_CONFDATA | (reg & 0x2));
124 mutex_exit(&pcicfg_mutex);
125 return (val);
128 uint32_t
129 pci_mech1_amd_getl(int bus, int device, int function, int reg)
131 uint32_t val;
133 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
134 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
135 return (0xffffffffu);
138 mutex_enter(&pcicfg_mutex);
139 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
140 val = inl(PCI_CONFDATA);
141 mutex_exit(&pcicfg_mutex);
142 return (val);
145 void
146 pci_mech1_amd_putb(int bus, int device, int function, int reg, uint8_t val)
148 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
149 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
150 return;
153 mutex_enter(&pcicfg_mutex);
154 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
155 outb(PCI_CONFDATA | (reg & 0x3), val);
156 mutex_exit(&pcicfg_mutex);
159 void
160 pci_mech1_amd_putw(int bus, int device, int function, int reg, uint16_t val)
162 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
163 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
164 return;
167 mutex_enter(&pcicfg_mutex);
168 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
169 outw(PCI_CONFDATA | (reg & 0x2), val);
170 mutex_exit(&pcicfg_mutex);
173 void
174 pci_mech1_amd_putl(int bus, int device, int function, int reg, uint32_t val)
176 if (device == PCI_MECH1_SPEC_CYCLE_DEV &&
177 function == PCI_MECH1_SPEC_CYCLE_FUNC) {
178 return;
181 mutex_enter(&pcicfg_mutex);
182 outl(PCI_CONFADD, PCI_CADDR1_ECS(bus, device, function, reg));
183 outl(PCI_CONFDATA, val);
184 mutex_exit(&pcicfg_mutex);