summaryrefslogtreecommitdiff
path: root/usr/src/uts/i86pc/i86hvm/io/pv_sd.c
blob: 74edb429073f805bf5219291bf42ce1e7658ea7f (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * 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 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#include <io/xdf_shell.h>

#include <sys/scsi/targets/sddef.h>

/*
 * We're emulating (and possibly layering on top of) sd devices, so xdf
 * disk unit mappings must match up with sd disk unit mappings'.
 */
#if !defined(XDF_PSHIFT)
#error "can't find definition for xdf unit mappings - XDF_PSHIFT"
#endif /* XDF_PSHIFT */

#if !defined(SDUNIT_SHIFT)
#error "can't find definition for cmdk unit mappings - SDUNIT_SHIFT"
#endif /* SDUNIT_SHIFT */

#if ((XDF_PSHIFT - SDUNIT_SHIFT) != 0)
#error "sd and xdf unit mappings don't match."
#endif /* ((XDF_PSHIFT - SDUNIT_SHIFT) != 0) */

extern const struct dev_ops	sd_ops;
extern void			*sd_state;

/*
 * Globals required by xdf_shell.c
 */
const char		*xdfs_c_name = "sd";
const char		*xdfs_c_linkinfo = "PV SCSI Disk Driver";
void			**xdfs_c_hvm_ss = &sd_state;
const size_t		xdfs_c_hvm_ss_size = sizeof (struct sd_lun);
const struct dev_ops	*xdfs_c_hvm_dev_ops = &sd_ops;

const xdfs_h2p_map_t xdfs_c_h2p_map[] = {
	{ "/pci@0,0/pci-ide@1,1/ide@0/sd@0,0", "/xpvd/xdf@768" },
	{ "/pci@0,0/pci-ide@1,1/ide@0/sd@1,0", "/xpvd/xdf@832" },
	{ "/pci@0,0/pci-ide@1,1/ide@1/sd@0,0", "/xpvd/xdf@5632" },
	{ "/pci@0,0/pci-ide@1,1/ide@1/sd@1,0", "/xpvd/xdf@5696" },
	{ NULL, 0 }
};

/*ARGSUSED*/
int
xdfs_c_ioctl(xdfs_state_t *xsp, dev_t dev, int part,
    int cmd, intptr_t arg, int flag, cred_t *credp, int *rvalp, boolean_t *done)
{
	dev_info_t	*dip = xsp->xdfss_dip;
	int		instance = ddi_get_instance(dip);
	int		rv;

	*done = B_TRUE;
	switch (cmd) {
	case DKIOCINFO: {
		struct dk_cinfo	info;

		/* Pass on the ioctl request, save the response */
		if ((rv = ldi_ioctl(xsp->xdfss_tgt_lh[part],
		    cmd, (intptr_t)&info, FKIOCTL, credp, rvalp)) != 0)
			return (rv);

		/* Update controller info */
		info.dki_cnum = ddi_get_instance(ddi_get_parent(dip));
		(void) strlcpy(info.dki_cname,
		    ddi_get_name(ddi_get_parent(dip)), sizeof (info.dki_cname));

		/* Update unit info. */
		if (info.dki_ctype == DKC_VBD) {
			/*
			 * Normally a real scsi device would report the
			 * controller type as DKC_SCSI_CCS.  But we don't
			 * emulate a real scsi controller.  (Which becomes
			 * apparent if anyone tries to issue us a uscsi(7i)
			 * command.) So instead of reporting DKC_SCSI_CCS,
			 * we report DKC_UNKNOWN.
			 */
			info.dki_ctype = DKC_UNKNOWN;
		}
		info.dki_unit = instance;
		(void) strlcpy(info.dki_dname,
		    ddi_driver_name(dip), sizeof (info.dki_dname));
		info.dki_addr = 1;

		if (ddi_copyout(&info, (void *)arg, sizeof (info), flag))
			return (EFAULT);

		return (0);
	}
	default:
		*done = B_FALSE;
		return (0);
	} /* switch (cmd) */
	/*NOTREACHED*/
}

/*ARGSUSED*/
void
xdfs_c_devid_setup(xdfs_state_t *xsp)
{
	/*
	 * Currently we only support cdrom devices, which don't have
	 * devids associated with them.
	 */
	ASSERT("cdrom devices don't have a devid");
}

/*ARGSUSED*/
int
xdfs_c_getpgeom(dev_info_t *dip, cmlb_geom_t *pgeom)
{
	/*
	 * Currently we only support cdrom devices, which don't have
	 * a physical geometry, so this routine should never get
	 * invoked.
	 */
	ASSERT("cdrom devices don't have any physical geometry");
	return (-1);
}

/*ARGSUSED*/
boolean_t
xdfs_c_bb_check(xdfs_state_t *xsp)
{
	/*
	 * Currently we only support cdrom devices, which don't have
	 * bad blocks, so this routine should never get invoked.
	 */
	ASSERT("cdrom devices don't support bad block mappings");
	return (B_TRUE);
}

char *
xdfs_c_cmlb_node_type(xdfs_state_t *xsp)
{
	return (xsp->xdfss_tgt_is_cd ? DDI_NT_CD_CHAN : DDI_NT_BLOCK_CHAN);
}

/*ARGSUSED*/
int
xdfs_c_cmlb_alter_behavior(xdfs_state_t *xsp)
{
	return (0);
}

void
xdfs_c_attach(xdfs_state_t *xsp)
{
	dev_info_t	*dip = xsp->xdfss_dip;
	int		dtype = DTYPE_DIRECT;

	if (xsp->xdfss_tgt_is_cd) {
		dtype = DTYPE_RODIRECT;
		(void) ddi_prop_create(DDI_DEV_T_NONE, dip,
		    DDI_PROP_CANSLEEP, "removable-media", NULL, 0);
	}

	/*
	 * We use ndi_* instead of ddi_* because it will result in
	 * INQUIRY_DEVICE_TYPE being a hardware property instead
	 * or a driver property
	 */
	(void) ndi_prop_update_int(DDI_DEV_T_NONE, dip,
	    INQUIRY_DEVICE_TYPE, dtype);
}