xref: /titanic_41/usr/src/uts/i86pc/io/pciex/npe_misc.c (revision 25cf1a301a396c38e8adf52c15f537b80d2483f7)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 /*
31  *	Library file that has miscellaneous support for npe(7d)
32  */
33 
34 #include <sys/conf.h>
35 #include <sys/pci.h>
36 #include <sys/sunndi.h>
37 #include <sys/acpi/acpi.h>
38 #include <sys/acpi/acpi_pci.h>
39 #include <sys/acpica.h>
40 #include <io/pciex/pcie_ck804_boot.h>
41 
42 /*
43  * Prototype declaration
44  */
45 void	npe_query_acpi_mcfg(dev_info_t *dip);
46 void	npe_ck804_fix_aer_ptr(dev_info_t *child);
47 
48 /*
49  * Default ecfga base address
50  */
51 int64_t npe_default_ecfga_base = 0xE0000000;
52 
53 /*
54  * Query the MCFG table using ACPI.  If MCFG is found, setup the
55  * 'ecfga-base-address' (Enhanced Configuration Access base address)
56  * property accordingly.  Otherwise, set the value of the property
57  * to the default value.
58  */
59 void
60 npe_query_acpi_mcfg(dev_info_t *dip)
61 {
62 	MCFG_TABLE *mcfgp;
63 	CFG_BASE_ADDR_ALLOC *cfg_baap;
64 	char *cfg_baa_endp;
65 	uint64_t ecfga_base;
66 
67 	/* Query the MCFG table using ACPI */
68 	if (AcpiGetFirmwareTable(MCFG_SIG, 1, ACPI_LOGICAL_ADDRESSING,
69 	    (ACPI_TABLE_HEADER **)&mcfgp) == AE_OK) {
70 
71 		cfg_baap = (CFG_BASE_ADDR_ALLOC *)mcfgp->CfgBaseAddrAllocList;
72 		cfg_baa_endp = ((char *)mcfgp) + mcfgp->Length;
73 
74 		while ((char *)cfg_baap < cfg_baa_endp) {
75 			ecfga_base = ACPI_GET_ADDRESS(cfg_baap->base_addr);
76 			if (ecfga_base != (uint64_t)0) {
77 				/*
78 				 * Setup the 'ecfga-base-address' property to
79 				 * the base_addr found in the MCFG and return.
80 				 */
81 				(void) ndi_prop_update_int64(DDI_DEV_T_NONE,
82 				    dip, "ecfga-base-address", ecfga_base);
83 				return;
84 			}
85 			cfg_baap++;
86 		}
87 	}
88 	/*
89 	 * If MCFG is not found or ecfga_base is not found in MCFG table,
90 	 * set the 'ecfga-base-address' property to the default value.
91 	 */
92 	(void) ndi_prop_update_int64(DDI_DEV_T_NONE, dip,
93 	    "ecfga-base-address", npe_default_ecfga_base);
94 }
95 
96 
97 /*
98  * Enable reporting of AER capability next pointer.
99  * This needs to be done only for CK8-04 devices
100  * by setting NV_XVR_VEND_CYA1 (offset 0xf40) bit 13
101  * NOTE: BIOS is disabling this, it needs to be enabled temporarily
102  */
103 void
104 npe_ck804_fix_aer_ptr(dev_info_t *child)
105 {
106 	ushort_t		vid, did, cya1;
107 	ddi_acc_handle_t	config_handle;
108 
109 	if (pci_config_setup(child, &config_handle) != DDI_SUCCESS)
110 		return;
111 
112 	vid = pci_config_get16(config_handle, PCI_CONF_VENID);
113 	if (vid != NVIDIA_CK804_VENDOR_ID) {
114 		pci_config_teardown(&config_handle);
115 		return;
116 	}
117 
118 	did = pci_config_get16(config_handle, PCI_CONF_DEVID);
119 	if (did != NVIDIA_CK804_DEVICE_ID) {
120 		pci_config_teardown(&config_handle);
121 		return;
122 	}
123 
124 	cya1 =  pci_config_get16(config_handle, NVIDIA_CK804_VEND_CYA1_OFF);
125 	if (!(cya1 & ~NVIDIA_CK804_VEND_CYA1_ERPT_MASK))
126 		(void) pci_config_put16(config_handle,
127 		    NVIDIA_CK804_VEND_CYA1_OFF,
128 		    cya1 | NVIDIA_CK804_VEND_CYA1_ERPT_VAL);
129 
130 	pci_config_teardown(&config_handle);
131 }
132