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