xref: /titanic_41/usr/src/uts/sun4v/os/mach_ddi_impl.c (revision fc256490629fe68815f7e0f23cf9b3545720cfac)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*fc256490SJason Beloro  * Common Development and Distribution License (the "License").
6*fc256490SJason Beloro  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*fc256490SJason Beloro  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * sun4u specific DDI implementation
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
307c478bd9Sstevel@tonic-gate #include <sys/conf.h>
317c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
327c478bd9Sstevel@tonic-gate #include <sys/idprom.h>
337c478bd9Sstevel@tonic-gate #include <sys/promif.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Favored drivers of this implementation
387c478bd9Sstevel@tonic-gate  * architecture.  These drivers MUST be present for
397c478bd9Sstevel@tonic-gate  * the system to boot at all.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate char *impl_module_list[] = {
427c478bd9Sstevel@tonic-gate 	"rootnex",
437c478bd9Sstevel@tonic-gate 	"options",
447c478bd9Sstevel@tonic-gate 	"sad",		/* Referenced via init_tbl[] */
457c478bd9Sstevel@tonic-gate 	"pseudo",
467c478bd9Sstevel@tonic-gate 	"clone",
477c478bd9Sstevel@tonic-gate 	"scsi_vhci",
487c478bd9Sstevel@tonic-gate 	(char *)0
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Check the status of the device node passed as an argument.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  *	if ((status is OKAY) || (status is DISABLED))
557c478bd9Sstevel@tonic-gate  *		return DDI_SUCCESS
567c478bd9Sstevel@tonic-gate  *	else
577c478bd9Sstevel@tonic-gate  *		print a warning and return DDI_FAILURE
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
607c478bd9Sstevel@tonic-gate int
check_status(int id,char * buf,dev_info_t * parent)617c478bd9Sstevel@tonic-gate check_status(int id, char *buf, dev_info_t *parent)
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate 	char status_buf[64];
647c478bd9Sstevel@tonic-gate 	extern int status_okay(int, char *, int);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/*
677c478bd9Sstevel@tonic-gate 	 * is the status okay?
687c478bd9Sstevel@tonic-gate 	 */
697c478bd9Sstevel@tonic-gate 	if (status_okay(id, status_buf, sizeof (status_buf)))
707c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	return (DDI_FAILURE);
737c478bd9Sstevel@tonic-gate }
74*fc256490SJason Beloro 
75*fc256490SJason Beloro /*
76*fc256490SJason Beloro  * For Devices which are assigned to another logical domain, the
77*fc256490SJason Beloro  * firmware modifies the various PCI properties so that no
78*fc256490SJason Beloro  * driver will attach in the case where the OS instances does not
79*fc256490SJason Beloro  * support ldoms direct I/O.  Since we do not support it, we can
80*fc256490SJason Beloro  * restore those properties to their expected values.
81*fc256490SJason Beloro  * See FWARC/2009/535.
82*fc256490SJason Beloro  */
83*fc256490SJason Beloro /*ARGSUSED*/
84*fc256490SJason Beloro void
translate_devid(dev_info_t * dip)85*fc256490SJason Beloro translate_devid(dev_info_t *dip)
86*fc256490SJason Beloro {
87*fc256490SJason Beloro 	int devid, venid, ssid, ssvid, rev, class_code;
88*fc256490SJason Beloro 	char *new_compat[7];
89*fc256490SJason Beloro 	int i;
90*fc256490SJason Beloro 	int compat_entry_length = 30;
91*fc256490SJason Beloro 	int ncompat = 7;
92*fc256490SJason Beloro 
93*fc256490SJason Beloro 	if ((devid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
94*fc256490SJason Beloro 	    "real-device-id", -1)) == -1)
95*fc256490SJason Beloro 		return;
96*fc256490SJason Beloro 	if ((venid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
97*fc256490SJason Beloro 	    "real-vendor-id", -1)) == -1)
98*fc256490SJason Beloro 		return;
99*fc256490SJason Beloro 
100*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "device-id", devid);
101*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "vendor-id", venid);
102*fc256490SJason Beloro 
103*fc256490SJason Beloro 	class_code = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
104*fc256490SJason Beloro 	    "real-class-code", 0);
105*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "class-clode",
106*fc256490SJason Beloro 	    class_code);
107*fc256490SJason Beloro 
108*fc256490SJason Beloro 	ssvid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
109*fc256490SJason Beloro 	    "real-subsystem-vendor-id", -1);
110*fc256490SJason Beloro 	if (ssvid != -1)
111*fc256490SJason Beloro 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip,
112*fc256490SJason Beloro 		    "subsystem-vendor-id", ssvid);
113*fc256490SJason Beloro 
114*fc256490SJason Beloro 	ssid = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
115*fc256490SJason Beloro 	    "real-subsystem-id", -1);
116*fc256490SJason Beloro 	if (ssid != -1)
117*fc256490SJason Beloro 		(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "subsystem-id",
118*fc256490SJason Beloro 		    ssid);
119*fc256490SJason Beloro 
120*fc256490SJason Beloro 	rev = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
121*fc256490SJason Beloro 	    "real-revision-id", 0);
122*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "revision-id", rev);
123*fc256490SJason Beloro 
124*fc256490SJason Beloro 	for (i = 0; i < ncompat; ++i) {
125*fc256490SJason Beloro 		new_compat[i] = kmem_zalloc(compat_entry_length, KM_NOSLEEP);
126*fc256490SJason Beloro 		if (new_compat[i] == NULL) {
127*fc256490SJason Beloro 			cmn_err(CE_WARN, "translate_devid: kmem_alloc "
128*fc256490SJason Beloro 			    "failed\n");
129*fc256490SJason Beloro 			ncompat = i;
130*fc256490SJason Beloro 			goto cleanup;
131*fc256490SJason Beloro 		}
132*fc256490SJason Beloro 	}
133*fc256490SJason Beloro 
134*fc256490SJason Beloro 	(void) sprintf(new_compat[0], "pciex%x,%x.%x.%x.%x",
135*fc256490SJason Beloro 	    venid, devid, ssvid, ssid, rev);
136*fc256490SJason Beloro 	(void) sprintf(new_compat[1], "pciex%x,%x.%x.%x",
137*fc256490SJason Beloro 	    venid, devid, ssvid, ssid);
138*fc256490SJason Beloro 	(void) sprintf(new_compat[2], "pciex%x,%x.%x", venid, devid, rev);
139*fc256490SJason Beloro 	(void) sprintf(new_compat[3], "pciex%x,%x", venid, devid);
140*fc256490SJason Beloro 	(void) sprintf(new_compat[4], "pciexclass,%06x", class_code);
141*fc256490SJason Beloro 	(void) sprintf(new_compat[5], "pciexclass,%04x", class_code >> 8);
142*fc256490SJason Beloro 	(void) sprintf(new_compat[6], "pci%x,%x", venid, devid);
143*fc256490SJason Beloro 
144*fc256490SJason Beloro 	(void) ddi_prop_update_string_array(DDI_DEV_T_NONE, dip, "compatible",
145*fc256490SJason Beloro 	    (char **)new_compat, 7);
146*fc256490SJason Beloro 
147*fc256490SJason Beloro cleanup:
148*fc256490SJason Beloro 	for (i = 0; i < ncompat; ++i)
149*fc256490SJason Beloro 		kmem_free(new_compat[i], compat_entry_length);
150*fc256490SJason Beloro 
151*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "ddi-assigned", 0);
152*fc256490SJason Beloro 	(void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1);
153*fc256490SJason Beloro }
154