1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <mcamd_pcicfg.h>
#include <sys/pci_cfgspace.h>
struct _mc_pcicfg_hdl {
mc_t *cfh_mc;
enum mc_funcnum cfh_func;
ddi_acc_handle_t cfh_hdl;
};
static int
mccfgsetup(struct _mc_pcicfg_hdl *hdlp, mc_t *mc, enum mc_funcnum func)
{
hdlp->cfh_mc = mc;
hdlp->cfh_func = func;
if (mc->mc_funcs[func].mcf_devi == NULL)
return (DDI_FAILURE);
if (pci_config_setup(mc->mc_funcs[func].mcf_devi, &hdlp->cfh_hdl) !=
DDI_SUCCESS)
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
int
mc_pcicfg_setup(mc_t *mc, enum mc_funcnum func, mc_pcicfg_hdl_t *cookiep)
{
struct _mc_pcicfg_hdl *hdlp;
*cookiep = hdlp = kmem_alloc(sizeof (struct _mc_pcicfg_hdl), KM_SLEEP);
if (mccfgsetup(hdlp, mc, func) == DDI_FAILURE) {
kmem_free(hdlp, sizeof (*hdlp));
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
void
mc_pcicfg_teardown(mc_pcicfg_hdl_t cookie)
{
struct _mc_pcicfg_hdl *hdlp = cookie;
pci_config_teardown(&hdlp->cfh_hdl);
kmem_free(hdlp, sizeof (*hdlp));
}
uint32_t
mc_pcicfg_get32(mc_pcicfg_hdl_t cookie, off_t offset)
{
struct _mc_pcicfg_hdl *hdlp = cookie;
return (pci_config_get32(hdlp->cfh_hdl, offset));
}
void
mc_pcicfg_put32(mc_pcicfg_hdl_t cookie, off_t offset, uint32_t val)
{
struct _mc_pcicfg_hdl *hdlp = cookie;
pci_config_put32(hdlp->cfh_hdl, offset, val);
}
uint32_t
mc_pcicfg_get32_nohdl(mc_t *mc, enum mc_funcnum func, off_t offset)
{
return ((*pci_getl_func)(0, MC_AMD_DEV_OFFSET + mc->mc_props.mcp_num,
func, offset));
}
void
mc_pcicfg_put32_nohdl(mc_t *mc, enum mc_funcnum func, off_t offset,
uint32_t val)
{
(*pci_putl_func)(0, MC_AMD_DEV_OFFSET + mc->mc_props.mcp_num,
func, offset, val);
}
|