xref: /illumos-gate/usr/src/uts/sun4u/io/pci/pcix.c (revision 4f364e7c95ee7fd9d5bbeddc1940e92405bb0e72)
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 2006 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 #include <sys/types.h>
29 #include <sys/kmem.h>
30 #include <sys/async.h>
31 #include <sys/sysmacros.h>
32 #include <sys/sunddi.h>
33 #include <sys/sunndi.h>
34 #include <sys/ddi_impldefs.h>
35 #include <sys/ddi_implfuncs.h>
36 #include <sys/pci/pci_obj.h>
37 #include <sys/pci.h>
38 #include <sys/pci_cap.h>
39 
40 /*LINTLIBRARY*/
41 
42 void
43 pcix_set_cmd_reg(dev_info_t *child, uint16_t value)
44 {
45 	uint16_t pcix_cap_ptr, pcix_cmd;
46 	ddi_acc_handle_t handle;
47 
48 	if (pci_config_setup(child, &handle) != DDI_SUCCESS)
49 		return;
50 
51 	/*
52 	 * Only modify the Command Register of non-bridge functions.
53 	 */
54 	if ((pci_config_get8(handle, PCI_CONF_HEADER) & PCI_HEADER_TYPE_M)
55 		== PCI_HEADER_PPB)
56 		goto teardown;
57 
58 	if (PCI_CAP_LOCATE(handle, PCI_CAP_ID_PCIX, &pcix_cap_ptr) ==
59 		DDI_FAILURE)
60 		goto teardown;
61 
62 	DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: pcix_cap_ptr = %x\n",
63 		pcix_cap_ptr);
64 
65 	/*
66 	 * Read the PCI-X Command Register.
67 	 */
68 	if ((pcix_cmd = PCI_CAP_GET16(handle, NULL, pcix_cap_ptr, 2))
69 		== PCI_CAP_EINVAL16)
70 		goto teardown;
71 
72 	DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: PCI-X CMD Register "
73 		"(Before) %x\n", pcix_cmd);
74 
75 	pcix_cmd &= ~(0x1f << 2); /* clear bits 6-2 */
76 	pcix_cmd |= value;
77 
78 	DEBUG1(DBG_INIT_CLD, child, "pcix_set_cmd_reg: PCI-X CMD Register "
79 		"(After) %x\n", pcix_cmd);
80 
81 	PCI_CAP_PUT16(handle, NULL, pcix_cap_ptr, 2, pcix_cmd);
82 
83 teardown:
84 	pci_config_teardown(&handle);
85 }
86