10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51865Sdilpreet * Common Development and Distribution License (the "License").
61865Sdilpreet * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate * Intel 21554 PCI to PCI bus bridge nexus driver for sun4u platforms.
290Sstevel@tonic-gate * Please note that 21554 is not a transparent bridge.
300Sstevel@tonic-gate * This driver can be used when the 21554 bridge is used like a
310Sstevel@tonic-gate * transparent bridge. The host OBP or the OS PCI Resource Allocator
320Sstevel@tonic-gate * (during a hotplug/hotswap operation) must represent this device
330Sstevel@tonic-gate * as a nexus and do the device tree representation of the child
340Sstevel@tonic-gate * nodes underneath.
350Sstevel@tonic-gate * Interrupt routing of the children must be done as per the PCI
360Sstevel@tonic-gate * specifications recommendation similar to that of a transparent
370Sstevel@tonic-gate * bridge.
380Sstevel@tonic-gate * Address translations from secondary across primary can be 1:1
390Sstevel@tonic-gate * or non 1:1. Currently only 1:1 translations are supported.
400Sstevel@tonic-gate * Configuration cycles are indirect. Memory and IO cycles are direct.
410Sstevel@tonic-gate */
420Sstevel@tonic-gate
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate * INCLUDES
450Sstevel@tonic-gate */
460Sstevel@tonic-gate #include <sys/stat.h>
470Sstevel@tonic-gate #include <sys/conf.h>
480Sstevel@tonic-gate #include <sys/kmem.h>
490Sstevel@tonic-gate #include <sys/debug.h>
500Sstevel@tonic-gate #include <sys/modctl.h>
510Sstevel@tonic-gate #include <sys/autoconf.h>
520Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
530Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
540Sstevel@tonic-gate #include <sys/pci.h>
550Sstevel@tonic-gate #include <sys/pci/pci_nexus.h>
560Sstevel@tonic-gate #include <sys/pci/pci_regs.h>
570Sstevel@tonic-gate #include <sys/pci/db21554_config.h> /* 21554 configuration space registers */
580Sstevel@tonic-gate #include <sys/pci/db21554_csr.h> /* 21554 control status register layout */
590Sstevel@tonic-gate #include <sys/pci/db21554_ctrl.h> /* driver private control structure */
600Sstevel@tonic-gate #include <sys/pci/db21554_debug.h> /* driver debug declarations */
610Sstevel@tonic-gate #include <sys/ddi.h>
620Sstevel@tonic-gate #include <sys/sunddi.h>
630Sstevel@tonic-gate #include <sys/sunndi.h>
640Sstevel@tonic-gate #include <sys/fm/protocol.h>
650Sstevel@tonic-gate #include <sys/ddifm.h>
660Sstevel@tonic-gate #include <sys/promif.h>
670Sstevel@tonic-gate #include <sys/file.h>
680Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h>
690Sstevel@tonic-gate
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate * DEFINES.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate #define DB_DEBUG
74*7656SSherry.Moore@Sun.COM #define DB_MODINFO_DESCRIPTION "Intel/21554 pci-pci nexus"
750Sstevel@tonic-gate #define DB_DVMA_START 0xc0000000
760Sstevel@tonic-gate #define DB_DVMA_LEN 0x20000000
770Sstevel@tonic-gate
780Sstevel@tonic-gate #ifdef DB_DEBUG
790Sstevel@tonic-gate /* ioctl definitions */
800Sstevel@tonic-gate #define DB_PCI_READ_CONF_HEADER 1
810Sstevel@tonic-gate #define DEF_INVALID_REG_VAL -1
820Sstevel@tonic-gate
830Sstevel@tonic-gate /* Default values for secondary cache line and latency timer */
840Sstevel@tonic-gate #define DB_SEC_LATENCY_TIMER_VAL 0x40
850Sstevel@tonic-gate #define DB_SEC_CACHELN_SIZE_VAL 0x10
860Sstevel@tonic-gate
870Sstevel@tonic-gate /* complete chip status information */
880Sstevel@tonic-gate typedef struct db_pci_data {
890Sstevel@tonic-gate char name[256];
900Sstevel@tonic-gate uint32_t instance;
910Sstevel@tonic-gate db_pci_header_t pri_hdr;
920Sstevel@tonic-gate db_pci_header_t sec_hdr;
930Sstevel@tonic-gate db_conf_regs_t conf_regs;
940Sstevel@tonic-gate } db_pci_data_t;
950Sstevel@tonic-gate #endif
960Sstevel@tonic-gate
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate * LOCALS
990Sstevel@tonic-gate */
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * The next set of variables are control parameters for debug purposes only.
1030Sstevel@tonic-gate * Changing the default values as assigned below are not recommended.
1040Sstevel@tonic-gate * In some cases, the non-default values are mostly application specific and
1050Sstevel@tonic-gate * hence may not have been tested yet.
1060Sstevel@tonic-gate *
1070Sstevel@tonic-gate * db_conf_map_mode : specifies the access method used for generating
1080Sstevel@tonic-gate * configuration cycles. Default value indicates
1090Sstevel@tonic-gate * the indirect configuration method.
1100Sstevel@tonic-gate * db_io_map_mode : specifies the access method used for generating
1110Sstevel@tonic-gate * IO cycles. Default value indicates the direct
1120Sstevel@tonic-gate * method.
1130Sstevel@tonic-gate * db_pci_own_wait : For indirect cycles, indicates the wait period
1140Sstevel@tonic-gate * for acquiring the bus, when the bus is busy.
1150Sstevel@tonic-gate * db_pci_release_wait:For indirect cycles, indicates the wait period
1160Sstevel@tonic-gate * for releasing the bus when the bus is busy.
1170Sstevel@tonic-gate * db_pci_max_wait : max. wait time when bus is busy for indirect cycles
1180Sstevel@tonic-gate * db_set_latency_timer_register :
1190Sstevel@tonic-gate * when 1, the driver overwrites the OBP assigned
1200Sstevel@tonic-gate * latency timer register setting for every child
1210Sstevel@tonic-gate * device during child initialization.
1220Sstevel@tonic-gate * db_set_cache_line_size_register :
1230Sstevel@tonic-gate * when 1, the driver overwrites the OBP assigned
1240Sstevel@tonic-gate * cache line register setting for every child
1250Sstevel@tonic-gate * device during child initialization.
1260Sstevel@tonic-gate * db_use_config_own_bit:
1270Sstevel@tonic-gate * when 1, the driver will use the "config own bit"
1280Sstevel@tonic-gate * for accessing the configuration address and data
1290Sstevel@tonic-gate * registers.
1300Sstevel@tonic-gate */
1310Sstevel@tonic-gate static uint32_t db_pci_own_wait = DB_PCI_WAIT_MS;
1320Sstevel@tonic-gate static uint32_t db_pci_release_wait = DB_PCI_WAIT_MS;
1330Sstevel@tonic-gate static uint32_t db_pci_max_wait = DB_PCI_TIMEOUT;
1340Sstevel@tonic-gate static uint32_t db_conf_map_mode = DB_CONF_MAP_INDIRECT_CONF;
1350Sstevel@tonic-gate static uint32_t db_io_map_mode = DB_IO_MAP_DIRECT;
1360Sstevel@tonic-gate static uint32_t db_set_latency_timer_register = 1;
1370Sstevel@tonic-gate static uint32_t db_set_cache_line_size_register = 1;
1380Sstevel@tonic-gate static uint32_t db_use_config_own_bit = 0;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate /*
1410Sstevel@tonic-gate * Properties that can be set via .conf files.
1420Sstevel@tonic-gate */
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate * By default, we forward SERR# from secondary to primary. This behavior
1460Sstevel@tonic-gate * can be controlled via a property "serr-fwd-enable", type integer.
1470Sstevel@tonic-gate * Values are 0 or 1.
1480Sstevel@tonic-gate * 0 means 'do not forward SERR#'.
1490Sstevel@tonic-gate * 1 means forwards SERR# to the host. Should be the default.
1500Sstevel@tonic-gate */
1510Sstevel@tonic-gate static uint32_t db_serr_fwd_enable = 1;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate * The next set of parameters are performance tuning parameters.
1550Sstevel@tonic-gate * These are in the form of properties settable through a .conf file.
1560Sstevel@tonic-gate * In case if the properties are absent the following defaults are assumed.
1570Sstevel@tonic-gate * These initial default values can be overwritten via /etc/system also.
1580Sstevel@tonic-gate *
1590Sstevel@tonic-gate * -1 means no setting is done ie. we either get OBP assigned value
1600Sstevel@tonic-gate * or reset values (at hotplug time for example).
1610Sstevel@tonic-gate */
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate /* primary latency timer: property "p-latency-timer" : type integer */
1640Sstevel@tonic-gate static int8_t p_latency_timer = DEF_INVALID_REG_VAL;
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /* secondary latency timer: property "s-latency-timer": type integer */
1670Sstevel@tonic-gate /*
1680Sstevel@tonic-gate * Currently on the secondary side the latency timer is not
1690Sstevel@tonic-gate * set by the serial PROM which causes performance degradation.
1700Sstevel@tonic-gate * Set the secondary latency timer register.
1710Sstevel@tonic-gate */
1720Sstevel@tonic-gate static int8_t s_latency_timer = DB_SEC_LATENCY_TIMER_VAL;
1730Sstevel@tonic-gate
1740Sstevel@tonic-gate /* primary cache line size: property "p-cache-line-size" : type integer */
1750Sstevel@tonic-gate static int8_t p_cache_line_size = DEF_INVALID_REG_VAL;
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate /* secondary cache line size: property "s-cache-line-size" : type integer */
1780Sstevel@tonic-gate /*
1790Sstevel@tonic-gate * Currently on the secondary side the cache line size is not
1800Sstevel@tonic-gate * set by the serial PROM which causes performance degradation.
1810Sstevel@tonic-gate * Set the secondary cache line size register.
1820Sstevel@tonic-gate */
1830Sstevel@tonic-gate static int8_t s_cache_line_size = DB_SEC_CACHELN_SIZE_VAL;
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate * control primary posted write queue threshold limit:
1870Sstevel@tonic-gate * property "p-pwrite-threshold" : type integer : values are 0 or 1.
1880Sstevel@tonic-gate * 1 enables control. 0 does not, and is the default reset value.
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate static int8_t p_pwrite_threshold = DEF_INVALID_REG_VAL;
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate /*
1930Sstevel@tonic-gate * control secondary posted write queue threshold limit:
1940Sstevel@tonic-gate * property "s-pwrite-threshold" : type integer : values are 0 or 1.
1950Sstevel@tonic-gate * 1 enables control. 0 does not, and is the default reset value.
1960Sstevel@tonic-gate */
1970Sstevel@tonic-gate static int8_t s_pwrite_threshold = DEF_INVALID_REG_VAL;
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate * control read queue threshold for initiating delayed read transaction
2010Sstevel@tonic-gate * on primary bus.
2020Sstevel@tonic-gate * property "p-dread-threshold" : type integer: values are
2030Sstevel@tonic-gate *
2040Sstevel@tonic-gate * 0 : reset value, default behavior: at least 8DWords free for all MR
2050Sstevel@tonic-gate * 1 : reserved
2060Sstevel@tonic-gate * 2 : at least one cache line free for MRL and MRM, 8 DWords free for MR
2070Sstevel@tonic-gate * 3 : at least one cache line free for all MR
2080Sstevel@tonic-gate */
2090Sstevel@tonic-gate static int8_t p_dread_threshold = DEF_INVALID_REG_VAL;
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate /*
2120Sstevel@tonic-gate * control read queue threshold for initiating delayed read transaction
2130Sstevel@tonic-gate * on secondary bus.
2140Sstevel@tonic-gate * property "s-dread-threshold" : type integer: values are
2150Sstevel@tonic-gate *
2160Sstevel@tonic-gate * 0 : reset value, default behavior: at least 8DWords free for all MR
2170Sstevel@tonic-gate * 1 : reserved
2180Sstevel@tonic-gate * 2 : at least one cache line free for MRL and MRM, 8 DWords free for MR
2190Sstevel@tonic-gate * 3 : at least one cache line free for all MR
2200Sstevel@tonic-gate */
2210Sstevel@tonic-gate static int8_t s_dread_threshold = DEF_INVALID_REG_VAL;
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * control how 21554 issues delayed transactions on the target bus.
2250Sstevel@tonic-gate * property "delayed-trans-order" : type integer: values are 0 or 1.
2260Sstevel@tonic-gate * 1 means repeat transaction on same target on target retries.
2270Sstevel@tonic-gate * 0 is the reset/default value, and means enable round robin based
2280Sstevel@tonic-gate * reads on other targets in read queue on any target retries.
2290Sstevel@tonic-gate */
2300Sstevel@tonic-gate static int8_t delayed_trans_order = DEF_INVALID_REG_VAL;
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /*
2330Sstevel@tonic-gate * In case if the system DVMA information is not available, as it is
2340Sstevel@tonic-gate * prior to s28q1, the system dvma range can be set via these parameters.
2350Sstevel@tonic-gate */
2360Sstevel@tonic-gate static uint32_t db_dvma_start = DB_DVMA_START;
2370Sstevel@tonic-gate static uint32_t db_dvma_len = DB_DVMA_LEN;
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate * Default command register settings for all PCI nodes this nexus initializes.
2410Sstevel@tonic-gate */
2420Sstevel@tonic-gate static uint16_t db_command_default =
2430Sstevel@tonic-gate PCI_COMM_SERR_ENABLE |
2440Sstevel@tonic-gate PCI_COMM_PARITY_DETECT |
2450Sstevel@tonic-gate PCI_COMM_ME |
2460Sstevel@tonic-gate PCI_COMM_MAE |
2470Sstevel@tonic-gate PCI_COMM_IO |
2480Sstevel@tonic-gate PCI_COMM_BACK2BACK_ENAB |
2490Sstevel@tonic-gate PCI_COMM_MEMWR_INVAL;
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate static int db_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
2520Sstevel@tonic-gate static int db_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
2530Sstevel@tonic-gate static void db_get_perf_parameters(db_ctrl_t *dbp);
2540Sstevel@tonic-gate static void db_set_perf_parameters(db_ctrl_t *dbp);
2550Sstevel@tonic-gate static void db_enable_io(db_ctrl_t *dbp);
2560Sstevel@tonic-gate static void db_orientation(db_ctrl_t *dbp);
2570Sstevel@tonic-gate static void db_set_dvma_range(db_ctrl_t *dbp);
2580Sstevel@tonic-gate static int db_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
2590Sstevel@tonic-gate void **result);
2600Sstevel@tonic-gate static int db_pci_map(dev_info_t *, dev_info_t *, ddi_map_req_t *,
2610Sstevel@tonic-gate off_t, off_t, caddr_t *);
2620Sstevel@tonic-gate static int db_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
2630Sstevel@tonic-gate void *, void *);
2640Sstevel@tonic-gate static int db_intr_ops(dev_info_t *dip, dev_info_t *rdip,
2650Sstevel@tonic-gate ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp,
2660Sstevel@tonic-gate void *result);
2670Sstevel@tonic-gate static dev_info_t *db_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
2680Sstevel@tonic-gate static int db_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap,
2690Sstevel@tonic-gate ddi_iblock_cookie_t *ibc);
2700Sstevel@tonic-gate static void db_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle);
2710Sstevel@tonic-gate static void db_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle);
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate struct bus_ops db_bus_ops = {
2740Sstevel@tonic-gate BUSO_REV,
2750Sstevel@tonic-gate db_pci_map,
2760Sstevel@tonic-gate 0,
2770Sstevel@tonic-gate 0,
2780Sstevel@tonic-gate 0,
2790Sstevel@tonic-gate i_ddi_map_fault,
2800Sstevel@tonic-gate ddi_dma_map,
2810Sstevel@tonic-gate ddi_dma_allochdl,
2820Sstevel@tonic-gate ddi_dma_freehdl,
2830Sstevel@tonic-gate ddi_dma_bindhdl,
2840Sstevel@tonic-gate ddi_dma_unbindhdl,
2850Sstevel@tonic-gate ddi_dma_flush,
2860Sstevel@tonic-gate ddi_dma_win,
2870Sstevel@tonic-gate ddi_dma_mctl,
2880Sstevel@tonic-gate db_ctlops,
2890Sstevel@tonic-gate ddi_bus_prop_op,
2900Sstevel@tonic-gate ndi_busop_get_eventcookie,
2910Sstevel@tonic-gate ndi_busop_add_eventcall,
2920Sstevel@tonic-gate ndi_busop_remove_eventcall,
2930Sstevel@tonic-gate ndi_post_event,
2940Sstevel@tonic-gate 0,
2950Sstevel@tonic-gate 0,
2960Sstevel@tonic-gate 0,
2970Sstevel@tonic-gate db_fm_init_child,
2980Sstevel@tonic-gate NULL,
2990Sstevel@tonic-gate db_bus_enter,
3000Sstevel@tonic-gate db_bus_exit,
3010Sstevel@tonic-gate 0,
3020Sstevel@tonic-gate db_intr_ops
3030Sstevel@tonic-gate };
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate static int db_open(dev_t *dev_p, int flag, int otyp, cred_t *cred_p);
3060Sstevel@tonic-gate static int db_close(dev_t dev, int flag, int otyp, cred_t *cred_p);
3070Sstevel@tonic-gate static int db_ioctl(dev_t dev, int cmd, intptr_t arg, int flag,
3080Sstevel@tonic-gate cred_t *cred_p, int *rval_p);
3090Sstevel@tonic-gate #ifdef DB_DEBUG
3100Sstevel@tonic-gate static dev_info_t *db_lookup_child_name(db_ctrl_t *dbp, char *name,
3110Sstevel@tonic-gate int instance);
3120Sstevel@tonic-gate static void db_pci_get_header(ddi_acc_handle_t config_handle,
3130Sstevel@tonic-gate db_pci_header_t *ph, off_t hdr_off);
3140Sstevel@tonic-gate static void db_pci_get_conf_regs(ddi_acc_handle_t config_handle,
3150Sstevel@tonic-gate db_conf_regs_t *cr);
3160Sstevel@tonic-gate #endif /* DB_DEBUG */
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate #ifdef DEBUG
3190Sstevel@tonic-gate static void
3200Sstevel@tonic-gate db_debug(uint64_t func_id, dev_info_t *dip, char *fmt,
3210Sstevel@tonic-gate uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5);
3220Sstevel@tonic-gate #endif
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate static int db_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
3250Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp);
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate static struct cb_ops db_cb_ops = {
3280Sstevel@tonic-gate db_open, /* open */
3290Sstevel@tonic-gate db_close, /* close */
3300Sstevel@tonic-gate nulldev, /* strategy */
3310Sstevel@tonic-gate nulldev, /* print */
3320Sstevel@tonic-gate nulldev, /* dump */
3330Sstevel@tonic-gate nulldev, /* read */
3340Sstevel@tonic-gate nulldev, /* write */
3350Sstevel@tonic-gate db_ioctl, /* ioctl */
3360Sstevel@tonic-gate nodev, /* devmap */
3370Sstevel@tonic-gate nodev, /* mmap */
3380Sstevel@tonic-gate nodev, /* segmap */
3390Sstevel@tonic-gate nochpoll, /* poll */
3400Sstevel@tonic-gate db_prop_op, /* cb_prop_op */
3410Sstevel@tonic-gate NULL, /* streamtab */
3420Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
3430Sstevel@tonic-gate CB_REV, /* rev */
3440Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
3450Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
3460Sstevel@tonic-gate };
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate static uint8_t db_ddi_get8(ddi_acc_impl_t *handle, uint8_t *addr);
3490Sstevel@tonic-gate static uint16_t db_ddi_get16(ddi_acc_impl_t *handle, uint16_t *addr);
3500Sstevel@tonic-gate static uint32_t db_ddi_get32(ddi_acc_impl_t *handle, uint32_t *addr);
3510Sstevel@tonic-gate static uint64_t db_ddi_get64(ddi_acc_impl_t *handle, uint64_t *addr);
3520Sstevel@tonic-gate static void db_ddi_put8(ddi_acc_impl_t *handle, uint8_t *addr,
3530Sstevel@tonic-gate uint8_t data);
3540Sstevel@tonic-gate static void db_ddi_put16(ddi_acc_impl_t *handle, uint16_t *addr,
3550Sstevel@tonic-gate uint16_t data);
3560Sstevel@tonic-gate static void db_ddi_put32(ddi_acc_impl_t *handle, uint32_t *addr,
3570Sstevel@tonic-gate uint32_t data);
3580Sstevel@tonic-gate static void db_ddi_put64(ddi_acc_impl_t *handle, uint64_t *addr,
3590Sstevel@tonic-gate uint64_t data);
3600Sstevel@tonic-gate static void db_ddi_rep_get8(ddi_acc_impl_t *handle, uint8_t *host_addr,
3610Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags);
3620Sstevel@tonic-gate static void db_ddi_rep_get16(ddi_acc_impl_t *handle, uint16_t *host_addr,
3630Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags);
3640Sstevel@tonic-gate static void db_ddi_rep_get32(ddi_acc_impl_t *handle, uint32_t *host_addr,
3650Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags);
3660Sstevel@tonic-gate static void db_ddi_rep_get64(ddi_acc_impl_t *handle, uint64_t *host_addr,
3670Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags);
3680Sstevel@tonic-gate static void db_ddi_rep_put8(ddi_acc_impl_t *handle, uint8_t *host_addr,
3690Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags);
3700Sstevel@tonic-gate static void db_ddi_rep_put16(ddi_acc_impl_t *handle, uint16_t *host_addr,
3710Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags);
3720Sstevel@tonic-gate static void db_ddi_rep_put32(ddi_acc_impl_t *handle, uint32_t *host_addr,
3730Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags);
3740Sstevel@tonic-gate static void db_ddi_rep_put64(ddi_acc_impl_t *handle, uint64_t *host_addr,
3750Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags);
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate static struct dev_ops db_dev_ops = {
3780Sstevel@tonic-gate DEVO_REV, /* devo_rev */
3790Sstevel@tonic-gate 0, /* refcnt */
3800Sstevel@tonic-gate db_getinfo, /* info */
3810Sstevel@tonic-gate nulldev, /* identify */
3820Sstevel@tonic-gate nulldev, /* probe */
3830Sstevel@tonic-gate db_attach, /* attach */
3840Sstevel@tonic-gate db_detach, /* detach */
3850Sstevel@tonic-gate nulldev, /* reset */
3860Sstevel@tonic-gate &db_cb_ops, /* driver operations */
3870Sstevel@tonic-gate &db_bus_ops, /* bus operations */
388*7656SSherry.Moore@Sun.COM ddi_power,
389*7656SSherry.Moore@Sun.COM ddi_quiesce_not_supported, /* devo_quiesce */
3900Sstevel@tonic-gate };
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate /*
3940Sstevel@tonic-gate * Module linkage information for the kernel.
3950Sstevel@tonic-gate */
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate static struct modldrv modldrv = {
3980Sstevel@tonic-gate &mod_driverops, /* Type of module */
3990Sstevel@tonic-gate DB_MODINFO_DESCRIPTION,
4000Sstevel@tonic-gate &db_dev_ops /* driver ops */
4010Sstevel@tonic-gate };
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate static struct modlinkage modlinkage = {
4040Sstevel@tonic-gate MODREV_1,
4050Sstevel@tonic-gate (void *)&modldrv,
4060Sstevel@tonic-gate NULL
4070Sstevel@tonic-gate };
4080Sstevel@tonic-gate
4090Sstevel@tonic-gate /* soft state pointer and structure template. */
4100Sstevel@tonic-gate static void *db_state;
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate /*
4130Sstevel@tonic-gate * forward function declarations:
4140Sstevel@tonic-gate */
4150Sstevel@tonic-gate static void db_uninitchild(dev_info_t *);
4160Sstevel@tonic-gate static int db_initchild(dev_info_t *child);
4170Sstevel@tonic-gate static int db_create_pci_prop(dev_info_t *child);
4180Sstevel@tonic-gate static int db_save_config_regs(db_ctrl_t *dbp);
4190Sstevel@tonic-gate static int db_restore_config_regs(db_ctrl_t *dbp);
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate /*
4220Sstevel@tonic-gate * FMA error callback
4230Sstevel@tonic-gate * Register error handling callback with our parent. We will just call
4240Sstevel@tonic-gate * our children's error callbacks and return their status.
4250Sstevel@tonic-gate */
4260Sstevel@tonic-gate static int db_err_callback(dev_info_t *dip, ddi_fm_error_t *derr,
4270Sstevel@tonic-gate const void *impl_data);
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate /*
4300Sstevel@tonic-gate * init/fini routines to alloc/dealloc fm structures and
4310Sstevel@tonic-gate * register/unregister our callback.
4320Sstevel@tonic-gate */
4330Sstevel@tonic-gate static void db_fm_init(db_ctrl_t *db_p);
4340Sstevel@tonic-gate static void db_fm_fini(db_ctrl_t *db_p);
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate int
_init(void)4370Sstevel@tonic-gate _init(void)
4380Sstevel@tonic-gate {
4390Sstevel@tonic-gate int rc;
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate DB_DEBUG0(DB_INIT|DB_DONT_DISPLAY_DIP, NULL, "enter\n");
4420Sstevel@tonic-gate if (((rc = ddi_soft_state_init(&db_state,
443*7656SSherry.Moore@Sun.COM sizeof (db_ctrl_t), 1)) == 0) &&
444*7656SSherry.Moore@Sun.COM ((rc = mod_install(&modlinkage)) != 0))
4450Sstevel@tonic-gate ddi_soft_state_fini(&db_state);
4460Sstevel@tonic-gate DB_DEBUG1(DB_INIT|DB_DONT_DISPLAY_DIP, NULL, "exit rc=%d\n", rc);
4470Sstevel@tonic-gate return (rc);
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate int
_fini(void)4520Sstevel@tonic-gate _fini(void)
4530Sstevel@tonic-gate {
4540Sstevel@tonic-gate int rc;
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate DB_DEBUG0(DB_FINI|DB_DONT_DISPLAY_DIP, NULL, "enter\n");
4570Sstevel@tonic-gate if ((rc = mod_remove(&modlinkage)) == 0)
4580Sstevel@tonic-gate ddi_soft_state_fini(&db_state);
4590Sstevel@tonic-gate DB_DEBUG1(DB_FINI|DB_DONT_DISPLAY_DIP, NULL, "exit rc=%d\n", rc);
4600Sstevel@tonic-gate return (rc);
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate
4630Sstevel@tonic-gate int
_info(struct modinfo * modinfop)4640Sstevel@tonic-gate _info(struct modinfo *modinfop)
4650Sstevel@tonic-gate {
4660Sstevel@tonic-gate int rc;
4670Sstevel@tonic-gate rc = mod_info(&modlinkage, modinfop);
4680Sstevel@tonic-gate DB_DEBUG1(DB_INFO|DB_DONT_DISPLAY_DIP, NULL, "exit rc=%d\n", rc);
4690Sstevel@tonic-gate return (rc);
4700Sstevel@tonic-gate }
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate /*ARGSUSED*/
4730Sstevel@tonic-gate static int
db_getinfo(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)4740Sstevel@tonic-gate db_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
4750Sstevel@tonic-gate {
4760Sstevel@tonic-gate db_ctrl_t *dbp;
4770Sstevel@tonic-gate int rc = DDI_FAILURE;
4780Sstevel@tonic-gate minor_t minor = getminor((dev_t)arg);
4790Sstevel@tonic-gate int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate DB_DEBUG1(DB_GETINFO|DB_DONT_DISPLAY_DIP, dip, "enter:cmd=%d\n",
482*7656SSherry.Moore@Sun.COM infocmd);
4830Sstevel@tonic-gate
4840Sstevel@tonic-gate switch (infocmd) {
4850Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate if ((dbp = ddi_get_soft_state(db_state,
4880Sstevel@tonic-gate instance)) != NULL) {
4890Sstevel@tonic-gate *result = dbp->dip;
4900Sstevel@tonic-gate rc = DDI_SUCCESS;
4910Sstevel@tonic-gate } else
4920Sstevel@tonic-gate *result = NULL;
4930Sstevel@tonic-gate break;
4940Sstevel@tonic-gate
4950Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
496946Smathue *result = (void *)(uintptr_t)instance;
4970Sstevel@tonic-gate rc = DDI_SUCCESS;
4980Sstevel@tonic-gate break;
4990Sstevel@tonic-gate
5000Sstevel@tonic-gate default:
5010Sstevel@tonic-gate break;
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate DB_DEBUG2(DB_GETINFO|DB_DONT_DISPLAY_DIP, dip,
504*7656SSherry.Moore@Sun.COM "exit: result=%x, rc=%d\n", *result, rc);
5050Sstevel@tonic-gate
5060Sstevel@tonic-gate return (rc);
5070Sstevel@tonic-gate }
5080Sstevel@tonic-gate
5090Sstevel@tonic-gate static int
db_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)5100Sstevel@tonic-gate db_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
5110Sstevel@tonic-gate {
5120Sstevel@tonic-gate int instance = ddi_get_instance(dip);
5130Sstevel@tonic-gate db_ctrl_t *dbp;
5140Sstevel@tonic-gate int rc = DDI_SUCCESS;
5150Sstevel@tonic-gate ddi_device_acc_attr_t db_csr_attr = { /* CSR map attributes */
5160Sstevel@tonic-gate DDI_DEVICE_ATTR_V0,
5170Sstevel@tonic-gate DDI_STRUCTURE_LE_ACC,
5180Sstevel@tonic-gate DDI_STRICTORDER_ACC
5190Sstevel@tonic-gate };
5200Sstevel@tonic-gate off_t bar_size;
5210Sstevel@tonic-gate int range_size;
5220Sstevel@tonic-gate char name[32];
5230Sstevel@tonic-gate
5240Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "enter: cmd=%d\n", cmd);
5250Sstevel@tonic-gate switch (cmd) {
5260Sstevel@tonic-gate
5270Sstevel@tonic-gate case DDI_ATTACH:
5280Sstevel@tonic-gate if (ddi_soft_state_zalloc(db_state, instance) != DDI_SUCCESS) {
5290Sstevel@tonic-gate rc = DDI_FAILURE;
5300Sstevel@tonic-gate break;
5310Sstevel@tonic-gate }
5320Sstevel@tonic-gate
5330Sstevel@tonic-gate dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
5340Sstevel@tonic-gate
5350Sstevel@tonic-gate dbp->dip = dip;
5360Sstevel@tonic-gate mutex_init(&dbp->db_mutex, NULL, MUTEX_DRIVER, NULL);
5370Sstevel@tonic-gate dbp->db_soft_state = DB_SOFT_STATE_CLOSED;
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate * Cannot use pci_config_setup here as we'd need
5410Sstevel@tonic-gate * to get a pointer to the address map to be able
5420Sstevel@tonic-gate * to set the bus private handle during child map
5430Sstevel@tonic-gate * operation.
5440Sstevel@tonic-gate */
5450Sstevel@tonic-gate if ((rc = ddi_regs_map_setup(dip, DB_PCI_CONF_RNUMBER,
546*7656SSherry.Moore@Sun.COM (caddr_t *)&dbp->conf_io, DB_PCI_CONF_OFFSET,
547*7656SSherry.Moore@Sun.COM PCI_CONF_HDR_SIZE, &db_csr_attr, &dbp->conf_handle))
548*7656SSherry.Moore@Sun.COM != DDI_SUCCESS) {
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate cmn_err(CE_WARN,
551*7656SSherry.Moore@Sun.COM "%s#%d: cannot map configuration space",
552*7656SSherry.Moore@Sun.COM ddi_driver_name(dip), ddi_get_instance(dip));
5530Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
5540Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
5550Sstevel@tonic-gate rc = DDI_FAILURE;
5560Sstevel@tonic-gate break;
5570Sstevel@tonic-gate }
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate db_get_perf_parameters(dbp);
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate if (ddi_dev_regsize(dip, DB_CSR_MEMBAR_RNUMBER, &bar_size)
562*7656SSherry.Moore@Sun.COM != DDI_SUCCESS) {
5630Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: cannot get memory CSR size",
564*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
565*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
5660Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
5670Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
5680Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
5690Sstevel@tonic-gate rc = DDI_FAILURE;
5700Sstevel@tonic-gate break;
5710Sstevel@tonic-gate }
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate /* map memory CSR space */
5740Sstevel@tonic-gate if (ddi_regs_map_setup(dip, DB_CSR_MEMBAR_RNUMBER,
575*7656SSherry.Moore@Sun.COM (caddr_t *)&dbp->csr_mem, DB_CSR_MEM_OFFSET, bar_size,
576*7656SSherry.Moore@Sun.COM &db_csr_attr, &dbp->csr_mem_handle) != DDI_SUCCESS) {
5770Sstevel@tonic-gate
5780Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: cannot map memory CSR space",
579*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
580*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
5810Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
5820Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
5830Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
5840Sstevel@tonic-gate rc = DDI_FAILURE;
5850Sstevel@tonic-gate break;
5860Sstevel@tonic-gate }
5870Sstevel@tonic-gate
5880Sstevel@tonic-gate if (ddi_dev_regsize(dip, DB_CSR_IOBAR_RNUMBER, &bar_size)
589*7656SSherry.Moore@Sun.COM != DDI_SUCCESS) {
5900Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: cannot get IO CSR size",
591*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
592*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
5930Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_mem_handle);
5940Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
5950Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
5960Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
5970Sstevel@tonic-gate rc = DDI_FAILURE;
5980Sstevel@tonic-gate break;
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate
6010Sstevel@tonic-gate /*
6020Sstevel@tonic-gate * map IO CSR space. We need this map to initiate
6030Sstevel@tonic-gate * indirect configuration transactions as this is a better
6040Sstevel@tonic-gate * option than doing through configuration space map.
6050Sstevel@tonic-gate */
6060Sstevel@tonic-gate if (ddi_regs_map_setup(dip, DB_CSR_IOBAR_RNUMBER,
607*7656SSherry.Moore@Sun.COM (caddr_t *)&dbp->csr_io, DB_CSR_IO_OFFSET, bar_size,
608*7656SSherry.Moore@Sun.COM &db_csr_attr, &dbp->csr_io_handle) != DDI_SUCCESS) {
6090Sstevel@tonic-gate
6100Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: cannot map IO CSR space",
611*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
612*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
6130Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_mem_handle);
6140Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
6150Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
6160Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
6170Sstevel@tonic-gate rc = DDI_FAILURE;
6180Sstevel@tonic-gate break;
6190Sstevel@tonic-gate }
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate db_orientation(dbp);
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS) {
6240Sstevel@tonic-gate if (pcihp_init(dip) != DDI_SUCCESS)
6250Sstevel@tonic-gate cmn_err(CE_WARN,
6260Sstevel@tonic-gate "%s#%d: could not register with hotplug",
6270Sstevel@tonic-gate ddi_driver_name(dbp->dip),
6280Sstevel@tonic-gate ddi_get_instance(dbp->dip));
6290Sstevel@tonic-gate } else {
6300Sstevel@tonic-gate /*
6310Sstevel@tonic-gate * create minor node for devctl interfaces
6320Sstevel@tonic-gate */
6330Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR,
6340Sstevel@tonic-gate PCIHP_AP_MINOR_NUM(instance, PCIHP_DEVCTL_MINOR),
6350Sstevel@tonic-gate DDI_NT_NEXUS, 0) != DDI_SUCCESS) {
6360Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_io_handle);
6370Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_mem_handle);
6380Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
6390Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
6400Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
6410Sstevel@tonic-gate rc = DDI_FAILURE;
6420Sstevel@tonic-gate break;
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate }
6450Sstevel@tonic-gate
6460Sstevel@tonic-gate db_enable_io(dbp);
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate range_size = sizeof (dbp->range);
649506Scth if (ddi_getlongprop_buf(DDI_DEV_T_ANY, dip,
650*7656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "bus-range", (caddr_t)&dbp->range,
651*7656SSherry.Moore@Sun.COM &range_size) != DDI_SUCCESS) {
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate cmn_err(CE_WARN,
654*7656SSherry.Moore@Sun.COM "%s#%d: cannot get bus-range property",
655*7656SSherry.Moore@Sun.COM ddi_driver_name(dip), ddi_get_instance(dip));
6560Sstevel@tonic-gate
6570Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
6580Sstevel@tonic-gate (void) pcihp_uninit(dip);
6590Sstevel@tonic-gate else
6600Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl");
6610Sstevel@tonic-gate
6620Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_mem_handle);
6630Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_io_handle);
6640Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
6650Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
6660Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
6670Sstevel@tonic-gate rc = DDI_FAILURE;
6680Sstevel@tonic-gate break;
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate
6710Sstevel@tonic-gate (void) sprintf(name, "%d", instance);
6720Sstevel@tonic-gate
6730Sstevel@tonic-gate if (ddi_create_minor_node(dip, name, S_IFCHR,
6740Sstevel@tonic-gate PCIHP_AP_MINOR_NUM(instance, PCIHP_DEBUG_MINOR),
6750Sstevel@tonic-gate NULL, NULL) == DDI_FAILURE) {
6760Sstevel@tonic-gate cmn_err(CE_NOTE, "%s#%d: node creation failure",
677*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip), instance);
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate
6800Sstevel@tonic-gate mutex_init(&dbp->db_busown, NULL, MUTEX_DRIVER, NULL);
6810Sstevel@tonic-gate
6820Sstevel@tonic-gate db_fm_init(dbp);
6830Sstevel@tonic-gate ddi_report_dev(dip);
6840Sstevel@tonic-gate dbp->dev_state |= DB_ATTACHED;
6850Sstevel@tonic-gate
6860Sstevel@tonic-gate break;
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate case DDI_RESUME:
6890Sstevel@tonic-gate
6900Sstevel@tonic-gate /*
6910Sstevel@tonic-gate * Get the soft state structure for the bridge.
6920Sstevel@tonic-gate */
6930Sstevel@tonic-gate dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
6940Sstevel@tonic-gate db_enable_io(dbp);
6950Sstevel@tonic-gate (void) db_restore_config_regs(dbp);
6960Sstevel@tonic-gate dbp->dev_state &= ~DB_SUSPENDED;
6970Sstevel@tonic-gate break;
6980Sstevel@tonic-gate
6990Sstevel@tonic-gate default:
7000Sstevel@tonic-gate rc = DDI_FAILURE; /* not supported yet */
7010Sstevel@tonic-gate break;
7020Sstevel@tonic-gate }
7030Sstevel@tonic-gate
7040Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "exit: rc=%d\n", rc);
7050Sstevel@tonic-gate return (rc);
7060Sstevel@tonic-gate }
7070Sstevel@tonic-gate
7080Sstevel@tonic-gate static int
db_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)7090Sstevel@tonic-gate db_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
7100Sstevel@tonic-gate {
7110Sstevel@tonic-gate int instance = ddi_get_instance(dip);
7120Sstevel@tonic-gate db_ctrl_t *dbp;
7130Sstevel@tonic-gate int rc = DDI_SUCCESS;
7140Sstevel@tonic-gate char name[32];
7150Sstevel@tonic-gate
7160Sstevel@tonic-gate dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
7170Sstevel@tonic-gate
7180Sstevel@tonic-gate DB_DEBUG1(DB_DETACH, dip, "enter: cmd=%d\n", cmd);
7190Sstevel@tonic-gate
7200Sstevel@tonic-gate switch (cmd) {
7210Sstevel@tonic-gate
7220Sstevel@tonic-gate case DDI_DETACH :
7230Sstevel@tonic-gate db_fm_fini(dbp);
7240Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
7250Sstevel@tonic-gate if (pcihp_uninit(dip) == DDI_FAILURE)
7260Sstevel@tonic-gate return (DDI_FAILURE);
7270Sstevel@tonic-gate else
7280Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl");
7290Sstevel@tonic-gate
7300Sstevel@tonic-gate mutex_destroy(&dbp->db_busown);
7310Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_mem_handle);
7320Sstevel@tonic-gate ddi_regs_map_free(&dbp->csr_io_handle);
7330Sstevel@tonic-gate
7340Sstevel@tonic-gate ddi_regs_map_free(&dbp->conf_handle);
7350Sstevel@tonic-gate dbp->dev_state &= ~DB_ATTACHED;
7360Sstevel@tonic-gate (void) sprintf(name, "%d", instance);
7370Sstevel@tonic-gate ddi_remove_minor_node(dip, name);
7380Sstevel@tonic-gate mutex_destroy(&dbp->db_mutex);
7390Sstevel@tonic-gate ddi_soft_state_free(db_state, instance);
7400Sstevel@tonic-gate break;
7410Sstevel@tonic-gate
7420Sstevel@tonic-gate case DDI_SUSPEND :
7430Sstevel@tonic-gate if (db_save_config_regs(dbp) != DDI_SUCCESS) {
7440Sstevel@tonic-gate cmn_err(CE_WARN,
745*7656SSherry.Moore@Sun.COM "%s#%d: Ignoring Child state Suspend Error",
746*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
747*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
7480Sstevel@tonic-gate }
7490Sstevel@tonic-gate dbp->dev_state |= DB_SUSPENDED;
7500Sstevel@tonic-gate break;
7510Sstevel@tonic-gate
7520Sstevel@tonic-gate default :
7530Sstevel@tonic-gate rc = DDI_FAILURE;
7540Sstevel@tonic-gate break;
7550Sstevel@tonic-gate }
7560Sstevel@tonic-gate
7570Sstevel@tonic-gate DB_DEBUG1(DB_DETACH, dip, "exit: rc=%d\n", rc);
7580Sstevel@tonic-gate return (rc);
7590Sstevel@tonic-gate }
7600Sstevel@tonic-gate
7610Sstevel@tonic-gate static void
db_get_perf_parameters(db_ctrl_t * dbp)7620Sstevel@tonic-gate db_get_perf_parameters(db_ctrl_t *dbp)
7630Sstevel@tonic-gate {
7640Sstevel@tonic-gate dbp->p_latency_timer = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
765*7656SSherry.Moore@Sun.COM dbp->dip, 0, "p-latency-timer", p_latency_timer);
7660Sstevel@tonic-gate dbp->s_latency_timer = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
767*7656SSherry.Moore@Sun.COM dbp->dip, 0, "s-latency-timer", s_latency_timer);
7680Sstevel@tonic-gate dbp->p_cache_line_size = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
769*7656SSherry.Moore@Sun.COM dbp->dip, 0, "p-cache-line-size", p_cache_line_size);
7700Sstevel@tonic-gate dbp->s_cache_line_size = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
771*7656SSherry.Moore@Sun.COM dbp->dip, 0, "s-cache-line-size", s_cache_line_size);
7720Sstevel@tonic-gate dbp->p_pwrite_threshold = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
773*7656SSherry.Moore@Sun.COM dbp->dip, 0, "p-pwrite-threshold", p_pwrite_threshold);
7740Sstevel@tonic-gate dbp->s_pwrite_threshold = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
775*7656SSherry.Moore@Sun.COM dbp->dip, 0, "s-pwrite-threshold", s_pwrite_threshold);
7760Sstevel@tonic-gate dbp->p_dread_threshold = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
777*7656SSherry.Moore@Sun.COM dbp->dip, 0, "p-dread-threshold", p_dread_threshold);
7780Sstevel@tonic-gate dbp->s_dread_threshold = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
779*7656SSherry.Moore@Sun.COM dbp->dip, 0, "s-dread-threshold", s_dread_threshold);
7800Sstevel@tonic-gate dbp->delayed_trans_order = (int8_t)ddi_prop_get_int(DDI_DEV_T_ANY,
781*7656SSherry.Moore@Sun.COM dbp->dip, 0, "delayed-trans-order", delayed_trans_order);
7820Sstevel@tonic-gate }
7830Sstevel@tonic-gate
7840Sstevel@tonic-gate static void
db_set_perf_parameters(db_ctrl_t * dbp)7850Sstevel@tonic-gate db_set_perf_parameters(db_ctrl_t *dbp)
7860Sstevel@tonic-gate {
7870Sstevel@tonic-gate uint_t poffset = 0, soffset = 0;
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
7900Sstevel@tonic-gate poffset = DB_SCONF_PRI_HDR_OFF;
7910Sstevel@tonic-gate else
7920Sstevel@tonic-gate soffset = DB_PCONF_SEC_HDR_OFF;
7930Sstevel@tonic-gate
7940Sstevel@tonic-gate if ((dbp->p_latency_timer != (int8_t)DEF_INVALID_REG_VAL) &&
795*7656SSherry.Moore@Sun.COM (dbp->p_latency_timer != -1))
7960Sstevel@tonic-gate ddi_put8(dbp->conf_handle,
797*7656SSherry.Moore@Sun.COM (uint8_t *)dbp->conf_io+poffset+PCI_CONF_LATENCY_TIMER,
798*7656SSherry.Moore@Sun.COM dbp->p_latency_timer);
7990Sstevel@tonic-gate if ((dbp->s_latency_timer != (int8_t)DEF_INVALID_REG_VAL) &&
800*7656SSherry.Moore@Sun.COM (dbp->s_latency_timer != -1))
8010Sstevel@tonic-gate ddi_put8(dbp->conf_handle,
802*7656SSherry.Moore@Sun.COM (uint8_t *)dbp->conf_io+soffset+PCI_CONF_LATENCY_TIMER,
803*7656SSherry.Moore@Sun.COM dbp->s_latency_timer);
8040Sstevel@tonic-gate if ((dbp->p_cache_line_size != (int8_t)DEF_INVALID_REG_VAL) &&
805*7656SSherry.Moore@Sun.COM (dbp->p_cache_line_size != -1))
8060Sstevel@tonic-gate ddi_put8(dbp->conf_handle,
807*7656SSherry.Moore@Sun.COM (uint8_t *)dbp->conf_io+poffset+PCI_CONF_CACHE_LINESZ,
808*7656SSherry.Moore@Sun.COM dbp->p_cache_line_size);
8090Sstevel@tonic-gate if ((dbp->s_cache_line_size != (int8_t)DEF_INVALID_REG_VAL) &&
810*7656SSherry.Moore@Sun.COM (dbp->s_cache_line_size != -1))
8110Sstevel@tonic-gate ddi_put8(dbp->conf_handle,
812*7656SSherry.Moore@Sun.COM (uint8_t *)dbp->conf_io+soffset+PCI_CONF_CACHE_LINESZ,
813*7656SSherry.Moore@Sun.COM dbp->s_cache_line_size);
8140Sstevel@tonic-gate if ((dbp->p_pwrite_threshold != (int8_t)DEF_INVALID_REG_VAL) &&
815*7656SSherry.Moore@Sun.COM (dbp->p_pwrite_threshold != -1))
8160Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)
817*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1),
818*7656SSherry.Moore@Sun.COM (ddi_get16(dbp->conf_handle, (uint16_t *)
819*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1)) &
820*7656SSherry.Moore@Sun.COM ~P_PW_THRESHOLD) |
821*7656SSherry.Moore@Sun.COM (dbp->p_pwrite_threshold?P_PW_THRESHOLD:0));
8220Sstevel@tonic-gate if ((dbp->s_pwrite_threshold != (int8_t)DEF_INVALID_REG_VAL) &&
823*7656SSherry.Moore@Sun.COM (dbp->s_pwrite_threshold != -1))
8240Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)
825*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1),
826*7656SSherry.Moore@Sun.COM (ddi_get16(dbp->conf_handle, (uint16_t *)
827*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1)) &
828*7656SSherry.Moore@Sun.COM ~S_PW_THRESHOLD) |
829*7656SSherry.Moore@Sun.COM (dbp->s_pwrite_threshold?S_PW_THRESHOLD:0));
8300Sstevel@tonic-gate /* primary delayed read threshold. 0x01 is reserved ?. */
8310Sstevel@tonic-gate if ((dbp->p_dread_threshold != (int8_t)DEF_INVALID_REG_VAL) &&
832*7656SSherry.Moore@Sun.COM (dbp->p_dread_threshold != -1))
8330Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)
834*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1),
835*7656SSherry.Moore@Sun.COM ((ddi_get16(dbp->conf_handle, (uint16_t *)
836*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1)) &
837*7656SSherry.Moore@Sun.COM ~P_DREAD_THRESHOLD_MASK) |
838*7656SSherry.Moore@Sun.COM ((dbp->p_dread_threshold &
839*7656SSherry.Moore@Sun.COM DREAD_THRESHOLD_VALBITS)<<2)));
8400Sstevel@tonic-gate /* secondary delayed read threshold. 0x01 is reserved ?. */
8410Sstevel@tonic-gate if ((dbp->s_dread_threshold != (int8_t)DEF_INVALID_REG_VAL) &&
842*7656SSherry.Moore@Sun.COM (dbp->s_dread_threshold != -1))
8430Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)
844*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1),
845*7656SSherry.Moore@Sun.COM ((ddi_get16(dbp->conf_handle, (uint16_t *)
846*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL1)) &
847*7656SSherry.Moore@Sun.COM ~S_DREAD_THRESHOLD_MASK) |
848*7656SSherry.Moore@Sun.COM ((dbp->s_dread_threshold &
849*7656SSherry.Moore@Sun.COM DREAD_THRESHOLD_VALBITS)<<4)));
8500Sstevel@tonic-gate if ((dbp->delayed_trans_order != (int8_t)DEF_INVALID_REG_VAL) &&
851*7656SSherry.Moore@Sun.COM (dbp->delayed_trans_order != -1))
8520Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)
853*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL0),
854*7656SSherry.Moore@Sun.COM (ddi_get16(dbp->conf_handle, (uint16_t *)
855*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io+DB_CONF_CHIP_CTRL0)) &
856*7656SSherry.Moore@Sun.COM ~DELAYED_TRANS_ORDER) |
857*7656SSherry.Moore@Sun.COM (dbp->delayed_trans_order?DELAYED_TRANS_ORDER:0));
8580Sstevel@tonic-gate }
8590Sstevel@tonic-gate
8600Sstevel@tonic-gate static void
db_orientation(db_ctrl_t * dbp)8610Sstevel@tonic-gate db_orientation(db_ctrl_t *dbp)
8620Sstevel@tonic-gate {
8630Sstevel@tonic-gate dev_info_t *dip = dbp->dip;
8640Sstevel@tonic-gate uint8_t pif;
8650Sstevel@tonic-gate uint32_t mem1;
8660Sstevel@tonic-gate uint32_t newval;
8670Sstevel@tonic-gate
8680Sstevel@tonic-gate /*
8690Sstevel@tonic-gate * determine orientation of drawbridge and enable
8700Sstevel@tonic-gate * Upstream or Downstream path.
8710Sstevel@tonic-gate */
8720Sstevel@tonic-gate
8730Sstevel@tonic-gate /*
8740Sstevel@tonic-gate * if PIF is set correctly, use it to determine orientation
8750Sstevel@tonic-gate */
8760Sstevel@tonic-gate pif = ddi_get8(dbp->conf_handle, (uchar_t *)dbp->conf_io +
877*7656SSherry.Moore@Sun.COM PCI_CONF_PROGCLASS);
8780Sstevel@tonic-gate if (pif & 0xff) {
8790Sstevel@tonic-gate if (pif & DB_PIF_SECONDARY_TO_HOST) {
8800Sstevel@tonic-gate dbp->dev_state = DB_SECONDARY_NEXUS;
8810Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip,
882*7656SSherry.Moore@Sun.COM "db_orientation: pif secondary\n");
8830Sstevel@tonic-gate return;
8840Sstevel@tonic-gate }
8850Sstevel@tonic-gate if (pif & DB_PIF_PRIMARY_TO_HOST) {
8860Sstevel@tonic-gate dbp->dev_state = DB_PRIMARY_NEXUS;
8870Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip,
888*7656SSherry.Moore@Sun.COM "db_orientation: pif primary\n");
8890Sstevel@tonic-gate return;
8900Sstevel@tonic-gate }
8910Sstevel@tonic-gate /* otherwise, fall through */
8920Sstevel@tonic-gate }
8930Sstevel@tonic-gate
8940Sstevel@tonic-gate /*
8950Sstevel@tonic-gate * otherwise, test the chip directly by trying to write
8960Sstevel@tonic-gate * downstream mem1 setup register, only writeable from
8970Sstevel@tonic-gate * secondary.
8980Sstevel@tonic-gate */
8990Sstevel@tonic-gate mem1 = ddi_get32(dbp->conf_handle,
900*7656SSherry.Moore@Sun.COM (uint32_t *)((uchar_t *)dbp->conf_io +
901*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_SETUP));
9020Sstevel@tonic-gate
9030Sstevel@tonic-gate ddi_put32(dbp->conf_handle,
904*7656SSherry.Moore@Sun.COM (uint32_t *)((uchar_t *)(dbp->conf_io +
905*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_SETUP)), ~mem1);
9060Sstevel@tonic-gate
9070Sstevel@tonic-gate newval = ddi_get32(dbp->conf_handle,
908*7656SSherry.Moore@Sun.COM (uint32_t *)((uchar_t *)dbp->conf_io +
909*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_SETUP));
9100Sstevel@tonic-gate
9110Sstevel@tonic-gate if (newval == mem1)
9120Sstevel@tonic-gate /* we couldn't write it, orientation is primary */
9130Sstevel@tonic-gate dbp->dev_state = DB_PRIMARY_NEXUS;
9140Sstevel@tonic-gate else {
9150Sstevel@tonic-gate /*
9160Sstevel@tonic-gate * we could write it, therefore orientation secondary.
9170Sstevel@tonic-gate * restore mem1 value.
9180Sstevel@tonic-gate */
9190Sstevel@tonic-gate dbp->dev_state = DB_SECONDARY_NEXUS;
9200Sstevel@tonic-gate ddi_put32(dbp->conf_handle,
921*7656SSherry.Moore@Sun.COM (uint32_t *)((uchar_t *)(dbp->conf_io +
922*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_SETUP)), mem1);
9230Sstevel@tonic-gate }
9240Sstevel@tonic-gate
9250Sstevel@tonic-gate
9260Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
9270Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip, "db_orientation: chip primary\n");
9280Sstevel@tonic-gate } else {
9290Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip, "db_orientation: chip secondary\n");
9300Sstevel@tonic-gate }
9310Sstevel@tonic-gate }
9320Sstevel@tonic-gate
9330Sstevel@tonic-gate static void
db_enable_io(db_ctrl_t * dbp)9340Sstevel@tonic-gate db_enable_io(db_ctrl_t *dbp)
9350Sstevel@tonic-gate {
9360Sstevel@tonic-gate dev_info_t *dip = dbp->dip;
9370Sstevel@tonic-gate pci_regspec_t *reg;
9380Sstevel@tonic-gate int rcount, length, i;
9390Sstevel@tonic-gate uint32_t offset;
9400Sstevel@tonic-gate uint32_t p_offset, s_offset;
9410Sstevel@tonic-gate uint16_t regval;
9420Sstevel@tonic-gate uint16_t enable;
9430Sstevel@tonic-gate
9440Sstevel@tonic-gate /*
9450Sstevel@tonic-gate * Step 0:
9460Sstevel@tonic-gate * setup the primary and secondary offset and enable
9470Sstevel@tonic-gate * values based on the orientation of 21554.
9480Sstevel@tonic-gate */
9490Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
9500Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip, "db_enable_io: primary\n");
9510Sstevel@tonic-gate p_offset = 0;
9520Sstevel@tonic-gate s_offset = DB_SCONF_HDR_OFF;
9530Sstevel@tonic-gate enable = DS_ENABLE;
9540Sstevel@tonic-gate } else {
9550Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip, "db_enable_io: secondary\n");
9560Sstevel@tonic-gate p_offset = DB_SCONF_HDR_OFF;
9570Sstevel@tonic-gate s_offset = 0;
9580Sstevel@tonic-gate enable = US_ENABLE;
9590Sstevel@tonic-gate }
9600Sstevel@tonic-gate
9610Sstevel@tonic-gate db_set_perf_parameters(dbp);
9620Sstevel@tonic-gate db_set_dvma_range(dbp);
9630Sstevel@tonic-gate
9640Sstevel@tonic-gate /*
9650Sstevel@tonic-gate * Step 1:
9660Sstevel@tonic-gate * setup latency timer and cache line size parameters
9670Sstevel@tonic-gate * which are used for child initialization.
9680Sstevel@tonic-gate */
9690Sstevel@tonic-gate dbp->latency_timer = ddi_get8(dbp->conf_handle, (uint8_t *)
970*7656SSherry.Moore@Sun.COM ((caddr_t)dbp->conf_io+PCI_CONF_LATENCY_TIMER));
9710Sstevel@tonic-gate
9720Sstevel@tonic-gate dbp->cache_line_size = ddi_get8(dbp->conf_handle, (uint8_t *)
973*7656SSherry.Moore@Sun.COM ((caddr_t)dbp->conf_io+PCI_CONF_CACHE_LINESZ));
9740Sstevel@tonic-gate
9750Sstevel@tonic-gate DB_DEBUG2(DB_ATTACH, dip,
976*7656SSherry.Moore@Sun.COM "db_enable_io: latency %d, cache line size %d\n",
977*7656SSherry.Moore@Sun.COM dbp->latency_timer, dbp->cache_line_size);
9780Sstevel@tonic-gate
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate * Step 2: program command reg on both primary and secondary
9810Sstevel@tonic-gate * interfaces.
9820Sstevel@tonic-gate */
9830Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)((caddr_t)dbp->conf_io +
984*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_COMM)), db_command_default);
9850Sstevel@tonic-gate
9860Sstevel@tonic-gate ddi_put16(dbp->conf_handle, (uint16_t *)((caddr_t)dbp->conf_io +
987*7656SSherry.Moore@Sun.COM (off_t)(s_offset + PCI_CONF_COMM)), db_command_default);
9880Sstevel@tonic-gate
9890Sstevel@tonic-gate /*
9900Sstevel@tonic-gate * Step 3:
9910Sstevel@tonic-gate * set up translated base registers, using the primary/
9920Sstevel@tonic-gate * secondary interface pci configuration Base Address
9930Sstevel@tonic-gate * Registers (BAR's).
9940Sstevel@tonic-gate */
9950Sstevel@tonic-gate
9960Sstevel@tonic-gate /* mem0 translated base is setup for primary orientation only. */
9970Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
9980Sstevel@tonic-gate /*
9990Sstevel@tonic-gate * And only if the 21554 device node property indicates
10000Sstevel@tonic-gate * the size of base0 register to be larger than csr map
10010Sstevel@tonic-gate * space, DB_CSR_SIZE=4K.
10020Sstevel@tonic-gate *
10030Sstevel@tonic-gate * Note : Setting up 1:1 translations only (for now:), i.e.
10040Sstevel@tonic-gate * no look up table.
10050Sstevel@tonic-gate */
10060Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip,
1007*7656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "reg", (caddr_t)®,
1008*7656SSherry.Moore@Sun.COM &length) != DDI_PROP_SUCCESS) {
10090Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip,
1010*7656SSherry.Moore@Sun.COM "Failed to read reg property\n");
10110Sstevel@tonic-gate return;
10120Sstevel@tonic-gate }
10130Sstevel@tonic-gate
10140Sstevel@tonic-gate /* Find device node's base0 reg property and check its size */
10150Sstevel@tonic-gate rcount = length / sizeof (pci_regspec_t);
10160Sstevel@tonic-gate for (i = 0; i < rcount; i++) {
10170Sstevel@tonic-gate offset = PCI_REG_REG_G(reg[i].pci_phys_hi);
10180Sstevel@tonic-gate if ((offset == PCI_CONF_BASE0) &&
1019*7656SSherry.Moore@Sun.COM (reg[i].pci_size_low > DB_CSR_SIZE))
10200Sstevel@tonic-gate break;
10210Sstevel@tonic-gate }
10220Sstevel@tonic-gate
10230Sstevel@tonic-gate /*
10240Sstevel@tonic-gate * set up mem0 translated base, if base0 register was
10250Sstevel@tonic-gate * found and its size was larger than csr map space.
10260Sstevel@tonic-gate */
10270Sstevel@tonic-gate if (i != rcount) {
10280Sstevel@tonic-gate DB_DEBUG0(DB_ATTACH, dip,
1029*7656SSherry.Moore@Sun.COM "db_enable_io: setting up MEM0_TR_BASE\n");
10300Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "BASE0 register = %x\n",
1031*7656SSherry.Moore@Sun.COM pci_config_get32(dbp->conf_handle,
1032*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_BASE0)));
10330Sstevel@tonic-gate
10340Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1035*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_DS_MEM0_TR_BASE,
1036*7656SSherry.Moore@Sun.COM pci_config_get32(dbp->conf_handle,
1037*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_BASE0)));
10380Sstevel@tonic-gate
10390Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip,
1040*7656SSherry.Moore@Sun.COM "db_enable_io: MEM0_TR_BASE set value = %x\n",
1041*7656SSherry.Moore@Sun.COM pci_config_get32(dbp->conf_handle,
1042*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_DS_MEM0_TR_BASE));
10430Sstevel@tonic-gate }
10440Sstevel@tonic-gate kmem_free(reg, length);
10450Sstevel@tonic-gate }
10460Sstevel@tonic-gate
10470Sstevel@tonic-gate pci_config_put32(dbp->conf_handle, (off_t)DB_CONF_DS_IO_MEM1_TR_BASE,
1048*7656SSherry.Moore@Sun.COM ((pci_config_get32(dbp->conf_handle,
1049*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_BASE2))) & ~DB_IO_BIT));
10500Sstevel@tonic-gate
10510Sstevel@tonic-gate pci_config_put32(dbp->conf_handle, (off_t)DB_CONF_DS_MEM2_TR_BASE,
1052*7656SSherry.Moore@Sun.COM ((pci_config_get32(dbp->conf_handle,
1053*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_BASE3))) & ~DB_IO_BIT));
10540Sstevel@tonic-gate
10550Sstevel@tonic-gate pci_config_put32(dbp->conf_handle, (off_t)DB_CONF_DS_MEM3_TR_BASE,
1056*7656SSherry.Moore@Sun.COM ((pci_config_get32(dbp->conf_handle,
1057*7656SSherry.Moore@Sun.COM (off_t)(p_offset + PCI_CONF_BASE4))) & ~DB_IO_BIT));
10580Sstevel@tonic-gate
10590Sstevel@tonic-gate pci_config_put32(dbp->conf_handle, (off_t)DB_CONF_US_IO_MEM0_TR_BASE,
1060*7656SSherry.Moore@Sun.COM ((pci_config_get32(dbp->conf_handle,
1061*7656SSherry.Moore@Sun.COM (off_t)(s_offset + PCI_CONF_BASE2))) & ~DB_IO_BIT));
10620Sstevel@tonic-gate
10630Sstevel@tonic-gate pci_config_put32(dbp->conf_handle, (off_t)DB_CONF_US_MEM1_TR_BASE,
1064*7656SSherry.Moore@Sun.COM ((pci_config_get32(dbp->conf_handle,
1065*7656SSherry.Moore@Sun.COM (off_t)(s_offset + PCI_CONF_BASE3))) & ~DB_IO_BIT));
10660Sstevel@tonic-gate
10670Sstevel@tonic-gate /*
10680Sstevel@tonic-gate * Step 4: enable downstream (for primary orientation) or upstream
10690Sstevel@tonic-gate * (for secondary orientation) bits in Configuration Control
10700Sstevel@tonic-gate * and Status register, if not already enabled.
10710Sstevel@tonic-gate */
10720Sstevel@tonic-gate regval = pci_config_get16(dbp->conf_handle, (off_t)DB_CONF_CONF_CSR);
10730Sstevel@tonic-gate
10740Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "db_enable_io: CSR value before: %x\n",
1075*7656SSherry.Moore@Sun.COM regval);
10760Sstevel@tonic-gate
10770Sstevel@tonic-gate if (!(regval & enable)) {
10780Sstevel@tonic-gate /* enable down/upstream configuration transactions */
10790Sstevel@tonic-gate regval |= enable;
10800Sstevel@tonic-gate pci_config_put16(dbp->conf_handle, (off_t)DB_CONF_CONF_CSR,
1081*7656SSherry.Moore@Sun.COM regval);
10820Sstevel@tonic-gate regval = pci_config_get16(dbp->conf_handle,
1083*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_CONF_CSR);
10840Sstevel@tonic-gate }
10850Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "db_enable_io: CSR value after: %x\n",
1086*7656SSherry.Moore@Sun.COM regval);
10870Sstevel@tonic-gate
10880Sstevel@tonic-gate /*
10890Sstevel@tonic-gate * Step 5: enable downstream/upstream I/O (through CSR space)
10900Sstevel@tonic-gate */
10910Sstevel@tonic-gate regval = ddi_get16(dbp->csr_mem_handle,
1092*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->csr_mem + DB_CSR_IO_CSR));
10930Sstevel@tonic-gate
10940Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "db_enable_io: IO_CSR value before: %x\n",
1095*7656SSherry.Moore@Sun.COM regval);
10960Sstevel@tonic-gate if (!(regval & enable)) {
10970Sstevel@tonic-gate regval |= enable;
10980Sstevel@tonic-gate ddi_put16(dbp->csr_mem_handle,
1099*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->csr_mem +
1100*7656SSherry.Moore@Sun.COM DB_CSR_IO_CSR), regval);
11010Sstevel@tonic-gate
11020Sstevel@tonic-gate regval = ddi_get16(dbp->csr_mem_handle,
1103*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->csr_mem + DB_CSR_IO_CSR));
11040Sstevel@tonic-gate }
11050Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip, "db_enable_io: IO_CSR value after: %x\n",
1106*7656SSherry.Moore@Sun.COM regval);
11070Sstevel@tonic-gate
11080Sstevel@tonic-gate /*
11090Sstevel@tonic-gate * Step 6: if 21554 orientation is primary to host,
11100Sstevel@tonic-gate * forward SERR# to host.
11110Sstevel@tonic-gate */
11120Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
11130Sstevel@tonic-gate dbp->serr_fwd_enable = ddi_prop_get_int(DDI_DEV_T_ANY,
1114*7656SSherry.Moore@Sun.COM dbp->dip, 0, "serr-fwd-enable", db_serr_fwd_enable);
11150Sstevel@tonic-gate
11160Sstevel@tonic-gate regval = ddi_get16(dbp->conf_handle,
1117*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->conf_io +
1118*7656SSherry.Moore@Sun.COM DB_CONF_CHIP_CTRL0));
11190Sstevel@tonic-gate
11200Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip,
1121*7656SSherry.Moore@Sun.COM "db_enable_io: CHIP_CTRL0 value before: %x\n", regval);
11220Sstevel@tonic-gate
11230Sstevel@tonic-gate ddi_put16(dbp->conf_handle,
1124*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->conf_io +
1125*7656SSherry.Moore@Sun.COM DB_CONF_CHIP_CTRL0),
1126*7656SSherry.Moore@Sun.COM (regval & ~SERR_FWD) |
1127*7656SSherry.Moore@Sun.COM (dbp->serr_fwd_enable?SERR_FWD:0));
11280Sstevel@tonic-gate
11290Sstevel@tonic-gate regval = ddi_get16(dbp->conf_handle,
1130*7656SSherry.Moore@Sun.COM (uint16_t *)((uchar_t *)dbp->conf_io +
1131*7656SSherry.Moore@Sun.COM DB_CONF_CHIP_CTRL0));
11320Sstevel@tonic-gate
11330Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip,
1134*7656SSherry.Moore@Sun.COM "db_enable_io: CHIP_CTRL0 value after: %x\n", regval);
11350Sstevel@tonic-gate }
11360Sstevel@tonic-gate
11370Sstevel@tonic-gate /*
11380Sstevel@tonic-gate * Step 7: if orientation is secondary, make sure primary lockout
11390Sstevel@tonic-gate * disable is reset.
11400Sstevel@tonic-gate */
11410Sstevel@tonic-gate
11420Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS) {
11430Sstevel@tonic-gate regval = pci_config_get16(dbp->conf_handle,
1144*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_CHIP_CTRL0);
11450Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip,
1146*7656SSherry.Moore@Sun.COM "db_enable_io: chip ctrl (0x%x) before\n", regval);
11470Sstevel@tonic-gate if (regval & PLOCKOUT)
11480Sstevel@tonic-gate pci_config_put16(dbp->conf_handle,
1149*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_CHIP_CTRL0,
1150*7656SSherry.Moore@Sun.COM (regval & ~PLOCKOUT));
11510Sstevel@tonic-gate regval = pci_config_get16(dbp->conf_handle,
1152*7656SSherry.Moore@Sun.COM (off_t)DB_CONF_CHIP_CTRL0);
11530Sstevel@tonic-gate DB_DEBUG1(DB_ATTACH, dip,
1154*7656SSherry.Moore@Sun.COM "db_enable_io: chip ctrl (0x%x) after\n", regval);
11550Sstevel@tonic-gate }
11560Sstevel@tonic-gate }
11570Sstevel@tonic-gate
11580Sstevel@tonic-gate /*
11590Sstevel@tonic-gate * Set DVMA Address Range.
11600Sstevel@tonic-gate * This code is common to both orientations of the nexus driver.
11610Sstevel@tonic-gate */
11620Sstevel@tonic-gate static void
db_set_dvma_range(db_ctrl_t * dbp)11630Sstevel@tonic-gate db_set_dvma_range(db_ctrl_t *dbp)
11640Sstevel@tonic-gate {
11650Sstevel@tonic-gate uint32_t dvma_start = 0;
11660Sstevel@tonic-gate uint32_t dvma_len = 0;
11670Sstevel@tonic-gate uint64_t db_allocd = 0;
11680Sstevel@tonic-gate uint32_t *dvma_prop;
11690Sstevel@tonic-gate uint32_t dvma_size[2]; /* dvma size may span over 2 BARs */
11700Sstevel@tonic-gate uint32_t dvma_bar[2]; /* dvma range may span over 2 BARs */
11710Sstevel@tonic-gate int dvma_prop_len;
11720Sstevel@tonic-gate uint64_t new_dvma_start, new_dvma_len, new_dvma_end;
11730Sstevel@tonic-gate
11740Sstevel@tonic-gate /*
11750Sstevel@tonic-gate * Need to traverse up the tree looking for a
11760Sstevel@tonic-gate * "virtual-dma" property that specifies the
11770Sstevel@tonic-gate * HPB DVMA range.
11780Sstevel@tonic-gate */
11790Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_get_parent(dbp->dip), 0,
1180*7656SSherry.Moore@Sun.COM "virtual-dma", (caddr_t)&dvma_prop, &dvma_prop_len)
1181*7656SSherry.Moore@Sun.COM == DDI_SUCCESS) {
11820Sstevel@tonic-gate dvma_start = dvma_prop[0];
11830Sstevel@tonic-gate dvma_len = dvma_prop[1];
11840Sstevel@tonic-gate kmem_free((caddr_t)dvma_prop, dvma_prop_len);
11850Sstevel@tonic-gate } else {
11860Sstevel@tonic-gate /*
11870Sstevel@tonic-gate * For initial implementation, lets avoid a warning since this
11880Sstevel@tonic-gate * change has not been implemented in the host-pci nexus
11890Sstevel@tonic-gate * driver.
11900Sstevel@tonic-gate */
11910Sstevel@tonic-gate cmn_err(CE_WARN,
1192*7656SSherry.Moore@Sun.COM "%s#%d: Could not get \"virtual-dma\" property",
1193*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
1194*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
11950Sstevel@tonic-gate dvma_start = db_dvma_start;
11960Sstevel@tonic-gate dvma_len = db_dvma_len;
11970Sstevel@tonic-gate }
11980Sstevel@tonic-gate
11990Sstevel@tonic-gate DB_DEBUG2(DB_DVMA, dbp->dip,
1200*7656SSherry.Moore@Sun.COM "DVMA Range is %lx,%lx\n", dvma_start, dvma_len);
12010Sstevel@tonic-gate
12020Sstevel@tonic-gate dvma_size[0] = dvma_size[1] = 0;
12030Sstevel@tonic-gate /* Validate DVMA size programming and system requirements. */
12040Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS) {
12050Sstevel@tonic-gate dvma_size[0] = pci_config_get32(dbp->conf_handle,
1206*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_SETUP);
12070Sstevel@tonic-gate if (!(dvma_size[0] & 1)) /* make sure it is not a IO BAR */
12080Sstevel@tonic-gate dvma_size[0] = ((~dvma_size[0]) + 1) & 0xfffff000;
12090Sstevel@tonic-gate else
12100Sstevel@tonic-gate dvma_size[0] = 0;
12110Sstevel@tonic-gate dvma_size[1] = db_dvma_len;
12120Sstevel@tonic-gate } else {
12130Sstevel@tonic-gate dvma_size[0] = pci_config_get32(dbp->conf_handle,
1214*7656SSherry.Moore@Sun.COM DB_CONF_US_IO_MEM0_SETUP);
12150Sstevel@tonic-gate if (!(dvma_size[0] & 1)) /* make sure it is not a IO BAR */
12160Sstevel@tonic-gate dvma_size[0] = ((~dvma_size[0]) + 1) & 0xfffff000;
12170Sstevel@tonic-gate else
12180Sstevel@tonic-gate dvma_size[0] = 0;
12190Sstevel@tonic-gate dvma_size[1] = ((~(pci_config_get32(dbp->conf_handle,
1220*7656SSherry.Moore@Sun.COM DB_CONF_US_MEM1_SETUP))) + 1) & 0xfffff000;
12210Sstevel@tonic-gate }
12220Sstevel@tonic-gate DB_DEBUG2(DB_DVMA, dbp->dip, "DVMA size register pair %lx, %lx\n",
1223*7656SSherry.Moore@Sun.COM dvma_size[0], dvma_size[1]);
12240Sstevel@tonic-gate
12250Sstevel@tonic-gate #ifdef DEBUG
12260Sstevel@tonic-gate if ((dvma_size[0] + dvma_size[1]) < dvma_len)
12270Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: DVMA window (%u) does not coincide"
12280Sstevel@tonic-gate " with system requirements",
1229*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip), ddi_get_instance(dbp->dip),
1230*7656SSherry.Moore@Sun.COM (dvma_size[0] + dvma_size[1]));
12310Sstevel@tonic-gate #endif
12320Sstevel@tonic-gate dvma_bar[0] = dvma_bar[1] = 0xFFFFFFFF;
12330Sstevel@tonic-gate db_allocd = 0;
12340Sstevel@tonic-gate new_dvma_start = dvma_start;
12350Sstevel@tonic-gate new_dvma_len = dvma_len;
12360Sstevel@tonic-gate
12370Sstevel@tonic-gate /* now, program the correct DVMA range over the 2 BARs. Max 4GB */
12380Sstevel@tonic-gate if (dvma_size[0]) {
12390Sstevel@tonic-gate dvma_bar[0] = (uint32_t)(dvma_start & (~(dvma_size[0] - 1)));
12400Sstevel@tonic-gate new_dvma_end = (uint64_t)((uint64_t)dvma_bar[0] +
1241*7656SSherry.Moore@Sun.COM (uint64_t)dvma_size[0]);
12420Sstevel@tonic-gate if (new_dvma_end > (new_dvma_start + new_dvma_len))
12430Sstevel@tonic-gate new_dvma_end = new_dvma_start + new_dvma_len;
12440Sstevel@tonic-gate db_allocd += (new_dvma_end - new_dvma_start);
12450Sstevel@tonic-gate new_dvma_start = new_dvma_end;
12460Sstevel@tonic-gate new_dvma_len = dvma_len - db_allocd;
12470Sstevel@tonic-gate }
12480Sstevel@tonic-gate /*
12490Sstevel@tonic-gate * It does not serve any purpose to set the other DVMA register
12500Sstevel@tonic-gate * when we have already met the memory requirements so leave it
12510Sstevel@tonic-gate * disabled.
12520Sstevel@tonic-gate */
12530Sstevel@tonic-gate if ((db_allocd != dvma_len) && dvma_size[1]) {
12540Sstevel@tonic-gate dvma_bar[1] = (uint32_t)((dvma_start + db_allocd) &
1255*7656SSherry.Moore@Sun.COM (~(dvma_size[1] - 1)));
12560Sstevel@tonic-gate new_dvma_end = (uint64_t)((uint64_t)dvma_bar[1] +
1257*7656SSherry.Moore@Sun.COM (uint64_t)dvma_size[1]);
12580Sstevel@tonic-gate if (new_dvma_end > (new_dvma_start + new_dvma_len))
12590Sstevel@tonic-gate new_dvma_end = new_dvma_start + new_dvma_len;
12600Sstevel@tonic-gate db_allocd += (new_dvma_end - new_dvma_start);
12610Sstevel@tonic-gate }
12620Sstevel@tonic-gate
12630Sstevel@tonic-gate /* In case of secondary orientation, DVMA BAR0 is 0. */
12640Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
12650Sstevel@tonic-gate dvma_bar[0] = 0;
12660Sstevel@tonic-gate
12670Sstevel@tonic-gate if (db_allocd != dvma_len) {
12680Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: dvma range error!",
1269*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip), ddi_get_instance(dbp->dip));
12700Sstevel@tonic-gate }
12710Sstevel@tonic-gate
12720Sstevel@tonic-gate DB_DEBUG2(DB_DVMA, dbp->dip, "DVMA BARs set as %x, %x\n",
1273*7656SSherry.Moore@Sun.COM dvma_bar[0], dvma_bar[1]);
12740Sstevel@tonic-gate
12750Sstevel@tonic-gate /* configure the setup register and DVMA BARs. */
12760Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS) {
12770Sstevel@tonic-gate if (dvma_bar[0] != 0xFFFFFFFF) {
12780Sstevel@tonic-gate #ifdef DB_SEC_SETUP_WRITE
12790Sstevel@tonic-gate /*
12800Sstevel@tonic-gate * No need to program the setup register
12810Sstevel@tonic-gate * as the PROM would have done it.
12820Sstevel@tonic-gate */
12830Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1284*7656SSherry.Moore@Sun.COM DB_CONF_DS_MEM1_SETUP,
1285*7656SSherry.Moore@Sun.COM (uint32_t)(((~(dvma_size[0] - 1)) |
1286*7656SSherry.Moore@Sun.COM (pci_config_get32(dbp->conf_handle,
1287*7656SSherry.Moore@Sun.COM DB_CONF_DS_MEM1_SETUP) & 0xF)) | 0x80000000));
12880Sstevel@tonic-gate #endif
12890Sstevel@tonic-gate /*
12900Sstevel@tonic-gate * when translations are to be provided, this will
12910Sstevel@tonic-gate * change.
12920Sstevel@tonic-gate */
12930Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1294*7656SSherry.Moore@Sun.COM DB_CONF_DS_IO_MEM1_TR_BASE,
1295*7656SSherry.Moore@Sun.COM (uint32_t)dvma_bar[0]);
12960Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1297*7656SSherry.Moore@Sun.COM DB_SCONF_DS_IO_MEM1, dvma_bar[0]);
12980Sstevel@tonic-gate }
12990Sstevel@tonic-gate if (dvma_bar[1] != 0xFFFFFFFF) {
13000Sstevel@tonic-gate #ifdef DB_SEC_SETUP_WRITE
13010Sstevel@tonic-gate /*
13020Sstevel@tonic-gate * No need to program the setup register
13030Sstevel@tonic-gate * as the PROM would have done it.
13040Sstevel@tonic-gate */
13050Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1306*7656SSherry.Moore@Sun.COM DB_CONF_DS_MEM2_SETUP,
1307*7656SSherry.Moore@Sun.COM (uint32_t)(((~(dvma_size[1] - 1)) |
1308*7656SSherry.Moore@Sun.COM (pci_config_get32(dbp->conf_handle,
1309*7656SSherry.Moore@Sun.COM DB_CONF_DS_MEM2_SETUP) & 0xF)) | 0x80000000));
13100Sstevel@tonic-gate #endif
13110Sstevel@tonic-gate /*
13120Sstevel@tonic-gate * when translations are to be provided, this will
13130Sstevel@tonic-gate * change.
13140Sstevel@tonic-gate */
13150Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1316*7656SSherry.Moore@Sun.COM DB_CONF_DS_MEM2_TR_BASE, (uint32_t)dvma_bar[1]);
13170Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1318*7656SSherry.Moore@Sun.COM DB_SCONF_DS_MEM2, dvma_bar[1]);
13190Sstevel@tonic-gate }
13200Sstevel@tonic-gate
13210Sstevel@tonic-gate } else {
13220Sstevel@tonic-gate if (dvma_bar[0] != 0xFFFFFFFF) {
13230Sstevel@tonic-gate #ifdef DB_CONF_P2S_WRITE_ENABLED /* primary to secondary write enabled */
13240Sstevel@tonic-gate /*
13250Sstevel@tonic-gate * We have a problem with this setup, because the
13260Sstevel@tonic-gate * US_MEM1 setup register cannot be written from the
13270Sstevel@tonic-gate * primary interface...!!! Hence in this configuration,
13280Sstevel@tonic-gate * we cannot dynamically program the DVMA range!
13290Sstevel@tonic-gate */
13300Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1331*7656SSherry.Moore@Sun.COM DB_CONF_US_IO_MEM0_SETUP,
1332*7656SSherry.Moore@Sun.COM (uint32_t)(((~(dvma_size[0] - 1)) |
1333*7656SSherry.Moore@Sun.COM (pci_config_get32(dbp->conf_handle,
1334*7656SSherry.Moore@Sun.COM DB_CONF_US_IO_MEM0_SETUP) & 0xF)) |
1335*7656SSherry.Moore@Sun.COM 0x80000000));
13360Sstevel@tonic-gate #endif
13370Sstevel@tonic-gate /*
13380Sstevel@tonic-gate * when translations are to be provided, this will
13390Sstevel@tonic-gate * change.
13400Sstevel@tonic-gate */
13410Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1342*7656SSherry.Moore@Sun.COM DB_CONF_US_IO_MEM0_TR_BASE,
1343*7656SSherry.Moore@Sun.COM (uint32_t)dvma_bar[0]);
13440Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1345*7656SSherry.Moore@Sun.COM DB_PCONF_US_IO_MEM0, dvma_bar[0]);
13460Sstevel@tonic-gate }
13470Sstevel@tonic-gate if (dvma_bar[1] != 0xFFFFFFFF) {
13480Sstevel@tonic-gate #ifdef DB_CONF_P2S_WRITE_ENABLED /* primary to secondary write enabled */
13490Sstevel@tonic-gate /*
13500Sstevel@tonic-gate * We have a problem with this setup, because the
13510Sstevel@tonic-gate * US_MEM1 setup register cannot be written from the
13520Sstevel@tonic-gate * primary interface...!!! Hence in this configuration,
13530Sstevel@tonic-gate * we cannot dynamically program the DVMA range!
13540Sstevel@tonic-gate */
13550Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1356*7656SSherry.Moore@Sun.COM DB_CONF_US_MEM1_SETUP,
1357*7656SSherry.Moore@Sun.COM (uint32_t)(((~(dvma_size[1] - 1)) |
1358*7656SSherry.Moore@Sun.COM (pci_config_get32(dbp->conf_handle,
1359*7656SSherry.Moore@Sun.COM DB_CONF_US_MEM1_SETUP) & 0xF)) | 0x80000000));
13600Sstevel@tonic-gate #endif
13610Sstevel@tonic-gate /*
13620Sstevel@tonic-gate * when translations are to be provided, this will
13630Sstevel@tonic-gate * change.
13640Sstevel@tonic-gate */
13650Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1366*7656SSherry.Moore@Sun.COM DB_CONF_US_MEM1_TR_BASE, (uint32_t)dvma_bar[1]);
13670Sstevel@tonic-gate pci_config_put32(dbp->conf_handle,
1368*7656SSherry.Moore@Sun.COM DB_PCONF_US_MEM1, dvma_bar[1]);
13690Sstevel@tonic-gate }
13700Sstevel@tonic-gate }
13710Sstevel@tonic-gate }
13720Sstevel@tonic-gate
13730Sstevel@tonic-gate /*ARGSUSED*/
13740Sstevel@tonic-gate static int
db_open(dev_t * dev_p,int flag,int otyp,cred_t * cred_p)13750Sstevel@tonic-gate db_open(dev_t *dev_p, int flag, int otyp, cred_t *cred_p)
13760Sstevel@tonic-gate {
13770Sstevel@tonic-gate minor_t minor = getminor(*dev_p);
13780Sstevel@tonic-gate int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
13790Sstevel@tonic-gate db_ctrl_t *dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
13800Sstevel@tonic-gate
13810Sstevel@tonic-gate if (dbp == (db_ctrl_t *)NULL)
13820Sstevel@tonic-gate return (ENXIO);
13830Sstevel@tonic-gate
13840Sstevel@tonic-gate /*
13850Sstevel@tonic-gate * check for debug node
13860Sstevel@tonic-gate */
13870Sstevel@tonic-gate if ((minor & 0xff) == 0xfe)
13880Sstevel@tonic-gate return (0);
13890Sstevel@tonic-gate
13900Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
13910Sstevel@tonic-gate return ((pcihp_get_cb_ops())->cb_open(dev_p, flag,
13920Sstevel@tonic-gate otyp, cred_p));
13930Sstevel@tonic-gate /*
13940Sstevel@tonic-gate * Handle the open by tracking the device state.
13950Sstevel@tonic-gate */
13960Sstevel@tonic-gate mutex_enter(&dbp->db_mutex);
13970Sstevel@tonic-gate if (flag & FEXCL) {
13980Sstevel@tonic-gate if (dbp->db_soft_state != DB_SOFT_STATE_CLOSED) {
13990Sstevel@tonic-gate mutex_exit(&dbp->db_mutex);
14000Sstevel@tonic-gate return (EBUSY);
14010Sstevel@tonic-gate }
14020Sstevel@tonic-gate dbp->db_soft_state = DB_SOFT_STATE_OPEN_EXCL;
14030Sstevel@tonic-gate } else {
14040Sstevel@tonic-gate if (dbp->db_soft_state == DB_SOFT_STATE_OPEN_EXCL) {
14050Sstevel@tonic-gate mutex_exit(&dbp->db_mutex);
14060Sstevel@tonic-gate return (EBUSY);
14070Sstevel@tonic-gate }
14080Sstevel@tonic-gate dbp->db_soft_state = DB_SOFT_STATE_OPEN;
14090Sstevel@tonic-gate }
14100Sstevel@tonic-gate mutex_exit(&dbp->db_mutex);
14110Sstevel@tonic-gate return (0);
14120Sstevel@tonic-gate }
14130Sstevel@tonic-gate
14140Sstevel@tonic-gate /*ARGSUSED*/
14150Sstevel@tonic-gate static int
db_close(dev_t dev,int flag,int otyp,cred_t * cred_p)14160Sstevel@tonic-gate db_close(dev_t dev, int flag, int otyp, cred_t *cred_p)
14170Sstevel@tonic-gate {
14180Sstevel@tonic-gate minor_t minor = getminor(dev);
14190Sstevel@tonic-gate int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
14200Sstevel@tonic-gate db_ctrl_t *dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
14210Sstevel@tonic-gate
14220Sstevel@tonic-gate if (dbp == (db_ctrl_t *)NULL)
14230Sstevel@tonic-gate return (ENXIO);
14240Sstevel@tonic-gate
14250Sstevel@tonic-gate /*
14260Sstevel@tonic-gate * check for debug node
14270Sstevel@tonic-gate */
14280Sstevel@tonic-gate if ((minor & 0xff) == 0xfe)
14290Sstevel@tonic-gate return (0);
14300Sstevel@tonic-gate
14310Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
14320Sstevel@tonic-gate return ((pcihp_get_cb_ops())->cb_close(dev, flag,
14330Sstevel@tonic-gate otyp, cred_p));
14340Sstevel@tonic-gate mutex_enter(&dbp->db_mutex);
14350Sstevel@tonic-gate dbp->db_soft_state = DB_SOFT_STATE_CLOSED;
14360Sstevel@tonic-gate mutex_exit(&dbp->db_mutex);
14370Sstevel@tonic-gate return (0);
14380Sstevel@tonic-gate }
14390Sstevel@tonic-gate
14400Sstevel@tonic-gate /*ARGSUSED*/
14410Sstevel@tonic-gate static int
db_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * cred_p,int * rval_p)14420Sstevel@tonic-gate db_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred_p,
14430Sstevel@tonic-gate int *rval_p)
14440Sstevel@tonic-gate {
14450Sstevel@tonic-gate int rc = DDI_SUCCESS;
14460Sstevel@tonic-gate #ifdef DB_DEBUG
14470Sstevel@tonic-gate ddi_acc_handle_t config_handle;
14480Sstevel@tonic-gate db_pci_data_t pci_data;
14490Sstevel@tonic-gate dev_info_t *child_dip;
14500Sstevel@tonic-gate #endif
14510Sstevel@tonic-gate dev_info_t *self;
14520Sstevel@tonic-gate minor_t minor = getminor(dev);
14530Sstevel@tonic-gate int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
14540Sstevel@tonic-gate struct devctl_iocdata *dcp;
14550Sstevel@tonic-gate uint_t bus_state;
14560Sstevel@tonic-gate db_ctrl_t *dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
14570Sstevel@tonic-gate
14580Sstevel@tonic-gate #ifdef DB_DEBUG
14590Sstevel@tonic-gate /*
14600Sstevel@tonic-gate * try this first whether were SECONDARY_NEXUS or not
14610Sstevel@tonic-gate */
14620Sstevel@tonic-gate if (cmd == DB_PCI_READ_CONF_HEADER) {
14630Sstevel@tonic-gate if (ddi_copyin((caddr_t)arg, (caddr_t)&pci_data,
1464*7656SSherry.Moore@Sun.COM sizeof (db_pci_data_t), mode)) {
14650Sstevel@tonic-gate rc = EFAULT;
14660Sstevel@tonic-gate return (rc);
14670Sstevel@tonic-gate }
14680Sstevel@tonic-gate
14690Sstevel@tonic-gate if (strcmp(pci_data.name, "") == 0) {
14700Sstevel@tonic-gate child_dip = dbp->dip;
14710Sstevel@tonic-gate (void) strcpy(pci_data.name,
1472*7656SSherry.Moore@Sun.COM ddi_get_name(dbp->dip));
14730Sstevel@tonic-gate } else {
14740Sstevel@tonic-gate
14750Sstevel@tonic-gate if ((child_dip = db_lookup_child_name(dbp,
1476*7656SSherry.Moore@Sun.COM pci_data.name, pci_data.instance))
1477*7656SSherry.Moore@Sun.COM == (dev_info_t *)NULL) {
14780Sstevel@tonic-gate rc = ENXIO;
14790Sstevel@tonic-gate return (rc);
14800Sstevel@tonic-gate } else {
14810Sstevel@tonic-gate if (ddi_getprop(DDI_DEV_T_ANY,
1482*7656SSherry.Moore@Sun.COM child_dip, DDI_PROP_DONTPASS,
1483*7656SSherry.Moore@Sun.COM "vendor-id", DB_INVAL_VEND)
1484*7656SSherry.Moore@Sun.COM == DB_INVAL_VEND) {
14850Sstevel@tonic-gate /* non PCI device */
14860Sstevel@tonic-gate rc = EINVAL;
14870Sstevel@tonic-gate return (rc);
14880Sstevel@tonic-gate }
14890Sstevel@tonic-gate }
14900Sstevel@tonic-gate }
14910Sstevel@tonic-gate pci_data.instance = ddi_get_instance(child_dip);
14920Sstevel@tonic-gate (void) pci_config_setup(child_dip, &config_handle);
14930Sstevel@tonic-gate db_pci_get_header(config_handle, &pci_data.pri_hdr, 0);
14940Sstevel@tonic-gate
14950Sstevel@tonic-gate /* if it is the drawbridge itself, read sec header */
14960Sstevel@tonic-gate if (child_dip == dbp->dip) {
14970Sstevel@tonic-gate db_pci_get_header(config_handle,
14980Sstevel@tonic-gate &pci_data.sec_hdr, DB_PCONF_SEC_HDR_OFF);
14990Sstevel@tonic-gate db_pci_get_conf_regs(config_handle,
15000Sstevel@tonic-gate &pci_data.conf_regs);
15010Sstevel@tonic-gate }
15020Sstevel@tonic-gate pci_config_teardown(&config_handle);
15030Sstevel@tonic-gate
15040Sstevel@tonic-gate if (ddi_copyout((caddr_t)&pci_data, (caddr_t)arg,
1505*7656SSherry.Moore@Sun.COM sizeof (db_pci_data_t), mode)) {
15060Sstevel@tonic-gate rc = EFAULT;
15070Sstevel@tonic-gate return (rc);
15080Sstevel@tonic-gate }
15090Sstevel@tonic-gate
15100Sstevel@tonic-gate return (rc);
15110Sstevel@tonic-gate }
15120Sstevel@tonic-gate #endif /* DB_DEBUG */
15130Sstevel@tonic-gate
15140Sstevel@tonic-gate /*
15150Sstevel@tonic-gate * if secondary nexus (hotplug), then use pcihp_ioctl to do everything
15160Sstevel@tonic-gate */
15170Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
15180Sstevel@tonic-gate return ((pcihp_get_cb_ops())->cb_ioctl(dev, cmd,
15190Sstevel@tonic-gate arg, mode, cred_p, rval_p));
15200Sstevel@tonic-gate
15210Sstevel@tonic-gate /*
15220Sstevel@tonic-gate * if not secondary nexus, we do DEVCTL_DEVICE and DEVCTL_BUS ourselves
15230Sstevel@tonic-gate */
15240Sstevel@tonic-gate self = dbp->dip;
15250Sstevel@tonic-gate
15260Sstevel@tonic-gate /*
15270Sstevel@tonic-gate * We can use the generic implementation for these ioctls
15280Sstevel@tonic-gate */
15290Sstevel@tonic-gate switch (cmd) {
15300Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE:
15310Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE:
15320Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE:
15330Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE:
15340Sstevel@tonic-gate return (ndi_devctl_ioctl(self, cmd, arg, mode, 0));
15350Sstevel@tonic-gate }
15360Sstevel@tonic-gate
15370Sstevel@tonic-gate /*
15380Sstevel@tonic-gate * read devctl ioctl data
15390Sstevel@tonic-gate */
15400Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS)
15410Sstevel@tonic-gate return (EFAULT);
15420Sstevel@tonic-gate
15430Sstevel@tonic-gate switch (cmd) {
15440Sstevel@tonic-gate
15450Sstevel@tonic-gate case DEVCTL_DEVICE_RESET:
15460Sstevel@tonic-gate rc = ENOTSUP;
15470Sstevel@tonic-gate break;
15480Sstevel@tonic-gate
15490Sstevel@tonic-gate
15500Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE:
15510Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
15520Sstevel@tonic-gate if (bus_state == BUS_QUIESCED)
15530Sstevel@tonic-gate break;
15540Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED);
15550Sstevel@tonic-gate break;
15560Sstevel@tonic-gate
15570Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE:
15580Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS)
15590Sstevel@tonic-gate if (bus_state == BUS_ACTIVE)
15600Sstevel@tonic-gate break;
15610Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE);
15620Sstevel@tonic-gate break;
15630Sstevel@tonic-gate
15640Sstevel@tonic-gate case DEVCTL_BUS_RESET:
15650Sstevel@tonic-gate rc = ENOTSUP;
15660Sstevel@tonic-gate break;
15670Sstevel@tonic-gate
15680Sstevel@tonic-gate case DEVCTL_BUS_RESETALL:
15690Sstevel@tonic-gate rc = ENOTSUP;
15700Sstevel@tonic-gate break;
15710Sstevel@tonic-gate
15720Sstevel@tonic-gate default:
15730Sstevel@tonic-gate rc = ENOTTY;
15740Sstevel@tonic-gate }
15750Sstevel@tonic-gate
15760Sstevel@tonic-gate ndi_dc_freehdl(dcp);
15770Sstevel@tonic-gate return (rc);
15780Sstevel@tonic-gate }
15790Sstevel@tonic-gate
15800Sstevel@tonic-gate #ifdef DB_DEBUG
15810Sstevel@tonic-gate static dev_info_t *
db_lookup_child_name(db_ctrl_t * dbp,char * name,int instance)15820Sstevel@tonic-gate db_lookup_child_name(db_ctrl_t *dbp, char *name, int instance)
15830Sstevel@tonic-gate {
15840Sstevel@tonic-gate dev_info_t *cdip, *pdip = dbp->dip;
15850Sstevel@tonic-gate
15860Sstevel@tonic-gate for (cdip = ddi_get_child(pdip); cdip;
1587*7656SSherry.Moore@Sun.COM cdip = ddi_get_next_sibling(pdip)) {
15880Sstevel@tonic-gate
15890Sstevel@tonic-gate do {
15900Sstevel@tonic-gate if (strcmp(ddi_node_name(cdip), name) == 0) {
15910Sstevel@tonic-gate if (instance != -1) {
15920Sstevel@tonic-gate if (ddi_get_instance(cdip) == instance)
15930Sstevel@tonic-gate return (cdip);
15940Sstevel@tonic-gate } else
15950Sstevel@tonic-gate return (cdip);
15960Sstevel@tonic-gate }
15970Sstevel@tonic-gate pdip = cdip;
15980Sstevel@tonic-gate } while ((cdip = ddi_get_child(pdip)));
15990Sstevel@tonic-gate cdip = ddi_get_next_sibling(pdip);
16000Sstevel@tonic-gate if (cdip == NULL) {
16010Sstevel@tonic-gate pdip = ddi_get_parent(pdip);
16020Sstevel@tonic-gate if (pdip == dbp->dip)
16030Sstevel@tonic-gate break;
16040Sstevel@tonic-gate }
16050Sstevel@tonic-gate }
16060Sstevel@tonic-gate return (NULL);
16070Sstevel@tonic-gate }
16080Sstevel@tonic-gate
16090Sstevel@tonic-gate static void
db_pci_get_header(ddi_acc_handle_t config_handle,db_pci_header_t * ph,off_t hdr_off)16100Sstevel@tonic-gate db_pci_get_header(ddi_acc_handle_t config_handle, db_pci_header_t *ph,
16110Sstevel@tonic-gate off_t hdr_off)
16120Sstevel@tonic-gate {
16130Sstevel@tonic-gate ph->venid = pci_config_get16(config_handle, hdr_off + PCI_CONF_VENID);
16140Sstevel@tonic-gate ph->devid = pci_config_get16(config_handle, hdr_off + PCI_CONF_DEVID);
16150Sstevel@tonic-gate ph->command = pci_config_get16(config_handle, hdr_off + PCI_CONF_COMM);
16160Sstevel@tonic-gate ph->status = pci_config_get16(config_handle, hdr_off + PCI_CONF_STAT);
16170Sstevel@tonic-gate ph->revid = pci_config_get8(config_handle, hdr_off + PCI_CONF_REVID);
16180Sstevel@tonic-gate ph->pif = pci_config_get8(config_handle, hdr_off + PCI_CONF_PROGCLASS);
16190Sstevel@tonic-gate ph->subclass = pci_config_get8(config_handle,
16200Sstevel@tonic-gate hdr_off + PCI_CONF_SUBCLASS);
16210Sstevel@tonic-gate ph->class = pci_config_get8(config_handle,
16220Sstevel@tonic-gate hdr_off + PCI_CONF_BASCLASS);
16230Sstevel@tonic-gate ph->cacheline = pci_config_get8(config_handle,
16240Sstevel@tonic-gate hdr_off + PCI_CONF_CACHE_LINESZ);
16250Sstevel@tonic-gate ph->lat = pci_config_get8(config_handle,
16260Sstevel@tonic-gate hdr_off + PCI_CONF_LATENCY_TIMER);
16270Sstevel@tonic-gate ph->hdr_type = pci_config_get8(config_handle,
16280Sstevel@tonic-gate hdr_off + PCI_CONF_HEADER);
16290Sstevel@tonic-gate ph->bist = pci_config_get8(config_handle, hdr_off + PCI_CONF_BIST);
16300Sstevel@tonic-gate ph->bar0 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE0);
16310Sstevel@tonic-gate ph->bar1 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE1);
16320Sstevel@tonic-gate ph->bar2 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE2);
16330Sstevel@tonic-gate ph->bar3 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE3);
16340Sstevel@tonic-gate ph->bar4 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE4);
16350Sstevel@tonic-gate ph->bar5 = pci_config_get32(config_handle, hdr_off + PCI_CONF_BASE5);
16360Sstevel@tonic-gate ph->cardbus_cisp = pci_config_get32(config_handle,
16370Sstevel@tonic-gate hdr_off + PCI_CONF_CIS);
16380Sstevel@tonic-gate ph->sub_venid = pci_config_get16(config_handle,
16390Sstevel@tonic-gate hdr_off + PCI_CONF_SUBVENID);
16400Sstevel@tonic-gate ph->sub_devid = pci_config_get16(config_handle,
16410Sstevel@tonic-gate hdr_off + PCI_CONF_SUBSYSID);
16420Sstevel@tonic-gate ph->exprom_bar = pci_config_get32(config_handle,
16430Sstevel@tonic-gate hdr_off + PCI_CONF_ROM);
16440Sstevel@tonic-gate ph->int_line = pci_config_get8(config_handle, hdr_off + PCI_CONF_ILINE);
16450Sstevel@tonic-gate ph->int_pin = pci_config_get8(config_handle, hdr_off + PCI_CONF_IPIN);
16460Sstevel@tonic-gate ph->min_gnt = pci_config_get8(config_handle, hdr_off + PCI_CONF_MIN_G);
16470Sstevel@tonic-gate ph->max_lat = pci_config_get8(config_handle, hdr_off + PCI_CONF_MAX_L);
16480Sstevel@tonic-gate }
16490Sstevel@tonic-gate
16500Sstevel@tonic-gate static void
db_pci_get_conf_regs(ddi_acc_handle_t config_handle,db_conf_regs_t * cr)16510Sstevel@tonic-gate db_pci_get_conf_regs(ddi_acc_handle_t config_handle, db_conf_regs_t *cr)
16520Sstevel@tonic-gate {
16530Sstevel@tonic-gate cr->ds_mem0_tr_base = pci_config_get32(config_handle,
16540Sstevel@tonic-gate DB_CONF_DS_MEM0_TR_BASE);
16550Sstevel@tonic-gate cr->ds_io_mem1_tr_base = pci_config_get32(config_handle,
16560Sstevel@tonic-gate DB_CONF_DS_IO_MEM1_TR_BASE);
16570Sstevel@tonic-gate cr->ds_mem2_tr_base = pci_config_get32(config_handle,
16580Sstevel@tonic-gate DB_CONF_DS_MEM2_TR_BASE);
16590Sstevel@tonic-gate cr->ds_mem3_tr_base = pci_config_get32(config_handle,
16600Sstevel@tonic-gate DB_CONF_DS_MEM3_TR_BASE);
16610Sstevel@tonic-gate cr->us_io_mem0_tr_base = pci_config_get32(config_handle,
16620Sstevel@tonic-gate DB_CONF_US_IO_MEM0_TR_BASE);
16630Sstevel@tonic-gate cr->us_mem1_tr_base = pci_config_get32(config_handle,
16640Sstevel@tonic-gate DB_CONF_US_MEM1_TR_BASE);
16650Sstevel@tonic-gate cr->ds_mem0_setup_reg = pci_config_get32(config_handle,
16660Sstevel@tonic-gate DB_CONF_DS_MEM0_SETUP);
16670Sstevel@tonic-gate cr->ds_io_mem1_setup_reg = pci_config_get32(config_handle,
16680Sstevel@tonic-gate DB_CONF_DS_IO_MEM1_SETUP);
16690Sstevel@tonic-gate cr->ds_mem2_setup_reg = pci_config_get32(config_handle,
16700Sstevel@tonic-gate DB_CONF_DS_MEM2_SETUP);
16710Sstevel@tonic-gate cr->ds_mem3_setup_reg = pci_config_get64(config_handle,
16720Sstevel@tonic-gate DB_CONF_DS_MEM3_SETUP);
16730Sstevel@tonic-gate cr->p_exp_rom_setup = pci_config_get32(config_handle,
16740Sstevel@tonic-gate DB_CONF_PRIM_EXP_ROM_SETUP);
16750Sstevel@tonic-gate cr->us_io_mem0_setup_reg = pci_config_get32(config_handle,
16760Sstevel@tonic-gate DB_CONF_US_IO_MEM0_SETUP);
16770Sstevel@tonic-gate cr->us_mem1_setup_reg = pci_config_get32(config_handle,
16780Sstevel@tonic-gate DB_CONF_US_MEM1_SETUP);
16790Sstevel@tonic-gate cr->chip_control0 = pci_config_get16(config_handle, DB_CONF_CHIP_CTRL0);
16800Sstevel@tonic-gate cr->chip_control1 = pci_config_get16(config_handle, DB_CONF_CHIP_CTRL1);
16810Sstevel@tonic-gate cr->chip_status = pci_config_get16(config_handle, DB_CONF_STATUS);
16820Sstevel@tonic-gate cr->arb_control = pci_config_get16(config_handle, DB_CONF_ARBITER_CTRL);
16830Sstevel@tonic-gate cr->p_serr_disables = pci_config_get8(config_handle,
16840Sstevel@tonic-gate DB_CONF_PRIM_SERR_DISABLES);
16850Sstevel@tonic-gate cr->s_serr_disables = pci_config_get8(config_handle,
16860Sstevel@tonic-gate DB_CONF_PRIM_SERR_DISABLES);
16870Sstevel@tonic-gate cr->config_csr = pci_config_get16(config_handle, DB_CONF_CONF_CSR);
16880Sstevel@tonic-gate cr->reset_control = pci_config_get32(config_handle, DB_CONF_RESET_CTRL);
16890Sstevel@tonic-gate cr->pm_cap = pci_config_get16(config_handle, DB_CONF_PM_CAP);
16900Sstevel@tonic-gate cr->pm_csr = pci_config_get16(config_handle, DB_CONF_PM_CSR);
16910Sstevel@tonic-gate cr->hs_csr = pci_config_get8(config_handle, DB_CONF_HS_CSR);
16920Sstevel@tonic-gate }
16930Sstevel@tonic-gate #endif /* DB_DEBUG */
16940Sstevel@tonic-gate
16950Sstevel@tonic-gate /*
16960Sstevel@tonic-gate * Function: db_pci_map
16970Sstevel@tonic-gate *
16980Sstevel@tonic-gate * Note: Only memory accesses are direct. IO could be direct
16990Sstevel@tonic-gate * or indirect. Config accesses are always indirect.
17000Sstevel@tonic-gate * The question here is, does the "assigned-addresses"
17010Sstevel@tonic-gate * property entry represents the addresses in the
17020Sstevel@tonic-gate * local domain or the host domain itself.
17030Sstevel@tonic-gate * Strictly speaking, the assumption should be that
17040Sstevel@tonic-gate * it is in the local domain, as the transactions
17050Sstevel@tonic-gate * upstream or downstream are automatically
17060Sstevel@tonic-gate * translated by the bridge chip anyway.
17070Sstevel@tonic-gate *
17080Sstevel@tonic-gate * Return values:
17090Sstevel@tonic-gate * DDI_SUCCESS: map call by child device success
17100Sstevel@tonic-gate * DDI_FAILURE: map operation failed.
17110Sstevel@tonic-gate */
17120Sstevel@tonic-gate
17130Sstevel@tonic-gate static int
db_pci_map(dev_info_t * dip,dev_info_t * rdip,ddi_map_req_t * mp,off_t offset,off_t len,caddr_t * addrp)17140Sstevel@tonic-gate db_pci_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
17150Sstevel@tonic-gate off_t offset, off_t len, caddr_t *addrp)
17160Sstevel@tonic-gate {
17170Sstevel@tonic-gate register dev_info_t *pdip;
17180Sstevel@tonic-gate int reg_proplen, num_regs, rnumber;
17190Sstevel@tonic-gate uint_t addr_space_type;
17200Sstevel@tonic-gate pci_regspec_t *pci_regsetp, pci_reg;
17210Sstevel@tonic-gate db_ctrl_t *dbp;
17220Sstevel@tonic-gate db_acc_pvt_t *db_pvt;
17230Sstevel@tonic-gate ddi_acc_impl_t *ap;
17240Sstevel@tonic-gate ddi_acc_hdl_t *hp;
17250Sstevel@tonic-gate db_acc_cfg_addr_t *pci_addr;
17260Sstevel@tonic-gate int instance = ddi_get_instance(dip);
17270Sstevel@tonic-gate
17280Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip, "enter\n");
17290Sstevel@tonic-gate
17300Sstevel@tonic-gate /* get map type. check for config space */
17310Sstevel@tonic-gate switch (mp->map_type) {
17320Sstevel@tonic-gate
17330Sstevel@tonic-gate case DDI_MT_RNUMBER :
17340Sstevel@tonic-gate /* get the reg number */
17350Sstevel@tonic-gate rnumber = mp->map_obj.rnumber;
17360Sstevel@tonic-gate
17370Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, rdip,
1738*7656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "reg",
1739*7656SSherry.Moore@Sun.COM (caddr_t)&pci_regsetp, ®_proplen)
1740*7656SSherry.Moore@Sun.COM != DDI_SUCCESS)
1741*7656SSherry.Moore@Sun.COM return (DDI_FAILURE);
17420Sstevel@tonic-gate
17430Sstevel@tonic-gate num_regs = reg_proplen / (int)sizeof (pci_regspec_t);
17440Sstevel@tonic-gate if (rnumber >= num_regs) {
17450Sstevel@tonic-gate /* this is a DDI_ME_RNUMBER_RANGE error */
17460Sstevel@tonic-gate kmem_free(pci_regsetp, reg_proplen);
17470Sstevel@tonic-gate return (DDI_FAILURE);
17480Sstevel@tonic-gate }
17490Sstevel@tonic-gate
17500Sstevel@tonic-gate pci_reg = pci_regsetp[rnumber];
17510Sstevel@tonic-gate kmem_free(pci_regsetp, reg_proplen);
17520Sstevel@tonic-gate /* FALLTHROUGH */
17530Sstevel@tonic-gate case DDI_MT_REGSPEC :
17540Sstevel@tonic-gate if (mp->map_type == DDI_MT_REGSPEC)
17550Sstevel@tonic-gate pci_reg = *(pci_regspec_t *)mp->map_obj.rp;
17560Sstevel@tonic-gate
17570Sstevel@tonic-gate /*
17580Sstevel@tonic-gate * Intercept config space accesses only. All other
17590Sstevel@tonic-gate * requests go to the parent.
17600Sstevel@tonic-gate */
17610Sstevel@tonic-gate addr_space_type = pci_reg.pci_phys_hi & PCI_ADDR_MASK;
17620Sstevel@tonic-gate
17630Sstevel@tonic-gate DB_DEBUG3(DB_PCI_MAP, dip, "rdip=%lx, rnum=%d(%d)\n",
1764*7656SSherry.Moore@Sun.COM rdip, rnumber, num_regs);
17650Sstevel@tonic-gate
17660Sstevel@tonic-gate /* if we do direct map IO, then lets break here */
17670Sstevel@tonic-gate if ((db_io_map_mode & DB_IO_MAP_DIRECT) &&
1768*7656SSherry.Moore@Sun.COM (addr_space_type == PCI_ADDR_IO))
17690Sstevel@tonic-gate break;
17700Sstevel@tonic-gate
17710Sstevel@tonic-gate if ((addr_space_type != PCI_ADDR_CONFIG) &&
1772*7656SSherry.Moore@Sun.COM (addr_space_type != PCI_ADDR_IO))
17730Sstevel@tonic-gate break;
17740Sstevel@tonic-gate
17750Sstevel@tonic-gate /*
17760Sstevel@tonic-gate * User mapping requests not legal for indirect
17770Sstevel@tonic-gate * IO/Config Space
17780Sstevel@tonic-gate */
17790Sstevel@tonic-gate if (mp->map_op == DDI_MO_MAP_HANDLE)
17800Sstevel@tonic-gate return (DDI_FAILURE);
17810Sstevel@tonic-gate
17820Sstevel@tonic-gate dbp = (db_ctrl_t *)ddi_get_soft_state(db_state,
1783*7656SSherry.Moore@Sun.COM instance);
17840Sstevel@tonic-gate /* get our common access handle */
17850Sstevel@tonic-gate hp = (ddi_acc_hdl_t *)mp->map_handlep;
17860Sstevel@tonic-gate
17870Sstevel@tonic-gate /* Check for unmap operation */
17880Sstevel@tonic-gate if ((mp->map_op == DDI_MO_UNMAP) ||
17890Sstevel@tonic-gate (mp->map_op == DDI_MO_UNLOCK)) {
17900Sstevel@tonic-gate /*
17910Sstevel@tonic-gate * free up memory allocated for our
17920Sstevel@tonic-gate * private access handle.
17930Sstevel@tonic-gate */
17940Sstevel@tonic-gate db_pvt = (db_acc_pvt_t *)
1795*7656SSherry.Moore@Sun.COM hp->ah_bus_private;
17960Sstevel@tonic-gate DB_DEBUG1(DB_PCI_MAP, dip,
1797*7656SSherry.Moore@Sun.COM "unmap rdip=%lx\n", rdip);
17980Sstevel@tonic-gate kmem_free((void *)db_pvt,
1799*7656SSherry.Moore@Sun.COM sizeof (db_acc_pvt_t));
18000Sstevel@tonic-gate
18010Sstevel@tonic-gate /*
18020Sstevel@tonic-gate * unmap operation of PCI IO/config
18030Sstevel@tonic-gate * space.
18040Sstevel@tonic-gate */
18050Sstevel@tonic-gate return (DDI_SUCCESS);
18060Sstevel@tonic-gate }
18070Sstevel@tonic-gate
18080Sstevel@tonic-gate if (addr_space_type == PCI_ADDR_CONFIG) {
18090Sstevel@tonic-gate /* Config space access range check */
18100Sstevel@tonic-gate if ((offset >= PCI_CONF_HDR_SIZE) ||
18110Sstevel@tonic-gate (len > PCI_CONF_HDR_SIZE) ||
18120Sstevel@tonic-gate (offset + len > PCI_CONF_HDR_SIZE)) {
18130Sstevel@tonic-gate
18140Sstevel@tonic-gate return (DDI_FAILURE);
18150Sstevel@tonic-gate }
18160Sstevel@tonic-gate }
18170Sstevel@tonic-gate
18180Sstevel@tonic-gate /* define the complete access handle */
18190Sstevel@tonic-gate hp = (ddi_acc_hdl_t *)mp->map_handlep;
18200Sstevel@tonic-gate
18210Sstevel@tonic-gate ap = (ddi_acc_impl_t *)hp->ah_platform_private;
18220Sstevel@tonic-gate
18230Sstevel@tonic-gate ap->ahi_get8 = db_ddi_get8;
18240Sstevel@tonic-gate ap->ahi_get16 = db_ddi_get16;
18250Sstevel@tonic-gate ap->ahi_get32 = db_ddi_get32;
18260Sstevel@tonic-gate ap->ahi_get64 = db_ddi_get64;
18270Sstevel@tonic-gate ap->ahi_put8 = db_ddi_put8;
18280Sstevel@tonic-gate ap->ahi_put16 = db_ddi_put16;
18290Sstevel@tonic-gate ap->ahi_put32 = db_ddi_put32;
18300Sstevel@tonic-gate ap->ahi_put64 = db_ddi_put64;
18310Sstevel@tonic-gate ap->ahi_rep_get8 = db_ddi_rep_get8;
18320Sstevel@tonic-gate ap->ahi_rep_get16 = db_ddi_rep_get16;
18330Sstevel@tonic-gate ap->ahi_rep_get32 = db_ddi_rep_get32;
18340Sstevel@tonic-gate ap->ahi_rep_get64 = db_ddi_rep_get64;
18350Sstevel@tonic-gate ap->ahi_rep_put8 = db_ddi_rep_put8;
18360Sstevel@tonic-gate ap->ahi_rep_put16 = db_ddi_rep_put16;
18370Sstevel@tonic-gate ap->ahi_rep_put32 = db_ddi_rep_put32;
18380Sstevel@tonic-gate ap->ahi_rep_put64 = db_ddi_rep_put64;
18390Sstevel@tonic-gate
18400Sstevel@tonic-gate /* Initialize to default check/notify functions */
18410Sstevel@tonic-gate ap->ahi_fault = 0;
18420Sstevel@tonic-gate ap->ahi_fault_check = i_ddi_acc_fault_check;
18430Sstevel@tonic-gate ap->ahi_fault_notify = i_ddi_acc_fault_notify;
18440Sstevel@tonic-gate
18450Sstevel@tonic-gate /* allocate memory for our private handle */
18460Sstevel@tonic-gate db_pvt = kmem_zalloc(sizeof (db_acc_pvt_t), KM_SLEEP);
18470Sstevel@tonic-gate hp->ah_bus_private = (void *)db_pvt;
18480Sstevel@tonic-gate db_pvt->dbp = dbp;
18490Sstevel@tonic-gate
18500Sstevel@tonic-gate /* record the device address for future use */
18510Sstevel@tonic-gate pci_addr = &db_pvt->dev_addr;
18520Sstevel@tonic-gate pci_addr->c_busnum =
1853*7656SSherry.Moore@Sun.COM PCI_REG_BUS_G(pci_reg.pci_phys_hi);
18540Sstevel@tonic-gate pci_addr->c_devnum =
1855*7656SSherry.Moore@Sun.COM PCI_REG_DEV_G(pci_reg.pci_phys_hi);
18560Sstevel@tonic-gate pci_addr->c_funcnum =
1857*7656SSherry.Moore@Sun.COM PCI_REG_FUNC_G(pci_reg.pci_phys_hi);
18580Sstevel@tonic-gate /*
18590Sstevel@tonic-gate * We should keep the upstream or
18600Sstevel@tonic-gate * downstream info in our own ah_bus_private
18610Sstevel@tonic-gate * structure, so that we do not waste our
18620Sstevel@tonic-gate * time in the actual IO routines, figuring out
18630Sstevel@tonic-gate * if we should use upstream or downstream
18640Sstevel@tonic-gate * configuration addr/data register.
18650Sstevel@tonic-gate * So, check orientation and setup registers
18660Sstevel@tonic-gate * right now.
18670Sstevel@tonic-gate */
18680Sstevel@tonic-gate switch (addr_space_type) {
18690Sstevel@tonic-gate
18700Sstevel@tonic-gate case PCI_ADDR_CONFIG :
18710Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
18720Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip, "primary\n");
18730Sstevel@tonic-gate db_pvt->mask = DS8_CONF_OWN;
18740Sstevel@tonic-gate if (db_conf_map_mode &
1875*7656SSherry.Moore@Sun.COM DB_CONF_MAP_INDIRECT_IO) {
18760Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1877*7656SSherry.Moore@Sun.COM "INDIRECT_CONF\n");
18780Sstevel@tonic-gate
18790Sstevel@tonic-gate db_pvt->handle =
1880*7656SSherry.Moore@Sun.COM dbp->csr_io_handle;
18810Sstevel@tonic-gate db_pvt->addr =
1882*7656SSherry.Moore@Sun.COM (uint32_t *)
1883*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1884*7656SSherry.Moore@Sun.COM + DB_CSR_DS_CONF_ADDR);
18850Sstevel@tonic-gate db_pvt->data =
1886*7656SSherry.Moore@Sun.COM (uint32_t *)
1887*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1888*7656SSherry.Moore@Sun.COM + DB_CSR_DS_CONF_DATA);
18890Sstevel@tonic-gate db_pvt->bus_own =
1890*7656SSherry.Moore@Sun.COM (uint8_t *)
1891*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1892*7656SSherry.Moore@Sun.COM + DB_CSR8_DS_CONF_OWN);
18930Sstevel@tonic-gate db_pvt->bus_release =
1894*7656SSherry.Moore@Sun.COM (uint8_t *)
1895*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1896*7656SSherry.Moore@Sun.COM + DB_CSR8_DS_CONF_CSR);
18970Sstevel@tonic-gate } else {
18980Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1899*7656SSherry.Moore@Sun.COM "DIRECT_CONF\n");
19000Sstevel@tonic-gate
19010Sstevel@tonic-gate db_pvt->handle =
1902*7656SSherry.Moore@Sun.COM dbp->conf_handle;
19030Sstevel@tonic-gate db_pvt->addr =
1904*7656SSherry.Moore@Sun.COM (uint32_t *)
1905*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1906*7656SSherry.Moore@Sun.COM + DB_CONF_DS_CONF_ADDR);
19070Sstevel@tonic-gate db_pvt->data = (uint32_t *)
1908*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1909*7656SSherry.Moore@Sun.COM + DB_CONF_DS_CONF_DATA);
19100Sstevel@tonic-gate db_pvt->bus_own =
1911*7656SSherry.Moore@Sun.COM (uint8_t *)
1912*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1913*7656SSherry.Moore@Sun.COM + DB_CONF8_DS_CONF_OWN);
19140Sstevel@tonic-gate db_pvt->bus_release =
1915*7656SSherry.Moore@Sun.COM (uint8_t *)
1916*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1917*7656SSherry.Moore@Sun.COM + DB_CONF8_DS_CONF_CSR);
19180Sstevel@tonic-gate }
19190Sstevel@tonic-gate } else {
19200Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1921*7656SSherry.Moore@Sun.COM "secondary\n");
19220Sstevel@tonic-gate db_pvt->mask = US8_CONF_OWN;
19230Sstevel@tonic-gate if (db_conf_map_mode &
1924*7656SSherry.Moore@Sun.COM DB_CONF_MAP_INDIRECT_IO) {
19250Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1926*7656SSherry.Moore@Sun.COM "INDIRECT_CONF\n");
19270Sstevel@tonic-gate
19280Sstevel@tonic-gate db_pvt->handle =
1929*7656SSherry.Moore@Sun.COM dbp->csr_io_handle;
19300Sstevel@tonic-gate db_pvt->addr =
1931*7656SSherry.Moore@Sun.COM (uint32_t *)
1932*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1933*7656SSherry.Moore@Sun.COM + DB_CSR_US_CONF_ADDR);
19340Sstevel@tonic-gate db_pvt->data =
1935*7656SSherry.Moore@Sun.COM (uint32_t *)
1936*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1937*7656SSherry.Moore@Sun.COM + DB_CSR_US_CONF_DATA);
19380Sstevel@tonic-gate db_pvt->bus_own =
1939*7656SSherry.Moore@Sun.COM (uint8_t *)
1940*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1941*7656SSherry.Moore@Sun.COM + DB_CSR8_US_CONF_OWN);
19420Sstevel@tonic-gate db_pvt->bus_release =
1943*7656SSherry.Moore@Sun.COM (uint8_t *)
1944*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1945*7656SSherry.Moore@Sun.COM + DB_CSR8_US_CONF_CSR);
19460Sstevel@tonic-gate } else {
19470Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1948*7656SSherry.Moore@Sun.COM "DIRECT_CONF\n");
19490Sstevel@tonic-gate
19500Sstevel@tonic-gate db_pvt->handle =
1951*7656SSherry.Moore@Sun.COM dbp->conf_handle;
19520Sstevel@tonic-gate db_pvt->addr =
1953*7656SSherry.Moore@Sun.COM (uint32_t *)
1954*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1955*7656SSherry.Moore@Sun.COM + DB_CONF_US_CONF_ADDR);
19560Sstevel@tonic-gate db_pvt->data =
1957*7656SSherry.Moore@Sun.COM (uint32_t *)
1958*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1959*7656SSherry.Moore@Sun.COM + DB_CONF_US_CONF_DATA);
19600Sstevel@tonic-gate db_pvt->bus_own =
1961*7656SSherry.Moore@Sun.COM (uint8_t *)
1962*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1963*7656SSherry.Moore@Sun.COM + DB_CONF8_US_CONF_OWN);
19640Sstevel@tonic-gate db_pvt->bus_release =
1965*7656SSherry.Moore@Sun.COM (uint8_t *)
1966*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->conf_io
1967*7656SSherry.Moore@Sun.COM + DB_CONF8_US_CONF_CSR);
19680Sstevel@tonic-gate }
19690Sstevel@tonic-gate }
19700Sstevel@tonic-gate break;
19710Sstevel@tonic-gate
19720Sstevel@tonic-gate case PCI_ADDR_IO :
19730Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip, "PCI_ADDR_IO\n");
19740Sstevel@tonic-gate
19750Sstevel@tonic-gate /* ap->ahi_acc_attr |= DDI_ACCATTR_IO_SPACE; */
19760Sstevel@tonic-gate db_pvt->handle = dbp->csr_io_handle;
19770Sstevel@tonic-gate if (dbp->dev_state & DB_PRIMARY_NEXUS) {
19780Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip, "primary\n");
19790Sstevel@tonic-gate db_pvt->addr = (uint32_t *)
1980*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1981*7656SSherry.Moore@Sun.COM + DB_CSR_DS_IO_ADDR);
19820Sstevel@tonic-gate db_pvt->data = (uint32_t *)
1983*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1984*7656SSherry.Moore@Sun.COM + DB_CSR_DS_IO_DATA);
19850Sstevel@tonic-gate db_pvt->bus_own = (uint8_t *)
1986*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1987*7656SSherry.Moore@Sun.COM + DB_CSR8_DS_IO_OWN);
19880Sstevel@tonic-gate db_pvt->bus_release = (uint8_t *)
1989*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1990*7656SSherry.Moore@Sun.COM + DB_CSR8_DS_IO_CSR);
19910Sstevel@tonic-gate db_pvt->mask = DS8_IO_OWN;
19920Sstevel@tonic-gate } else {
19930Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
1994*7656SSherry.Moore@Sun.COM "secondary\n");
19950Sstevel@tonic-gate db_pvt->addr = (uint32_t *)
1996*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
1997*7656SSherry.Moore@Sun.COM + DB_CSR_US_IO_ADDR);
19980Sstevel@tonic-gate db_pvt->data = (uint32_t *)
1999*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
2000*7656SSherry.Moore@Sun.COM + DB_CSR_US_IO_DATA);
20010Sstevel@tonic-gate db_pvt->bus_own = (uint8_t *)
2002*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
2003*7656SSherry.Moore@Sun.COM + DB_CSR8_US_IO_OWN);
20040Sstevel@tonic-gate db_pvt->bus_release = (uint8_t *)
2005*7656SSherry.Moore@Sun.COM ((uchar_t *)dbp->csr_io
2006*7656SSherry.Moore@Sun.COM + DB_CSR8_US_IO_CSR);
20070Sstevel@tonic-gate db_pvt->mask = US8_IO_OWN;
20080Sstevel@tonic-gate }
20090Sstevel@tonic-gate break;
20100Sstevel@tonic-gate
20110Sstevel@tonic-gate default :
20120Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
2013*7656SSherry.Moore@Sun.COM "PCI_ADDR unknown\n");
20140Sstevel@tonic-gate break;
20150Sstevel@tonic-gate }
20160Sstevel@tonic-gate
20170Sstevel@tonic-gate /* make and store a type 0/1 address in the *addrp */
20180Sstevel@tonic-gate if (pci_addr->c_busnum == dbp->range.lo) {
20190Sstevel@tonic-gate *addrp = (caddr_t)DB_PCI_REG_ADDR_TYPE0(
2020*7656SSherry.Moore@Sun.COM pci_addr->c_busnum,
2021*7656SSherry.Moore@Sun.COM pci_addr->c_devnum,
2022*7656SSherry.Moore@Sun.COM pci_addr->c_funcnum,
2023*7656SSherry.Moore@Sun.COM offset);
20240Sstevel@tonic-gate db_pvt->access_mode |= DB_PCI_CONF_CYCLE_TYPE0;
20250Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
2026*7656SSherry.Moore@Sun.COM "access mode type 0\n");
20270Sstevel@tonic-gate } else {
20280Sstevel@tonic-gate *addrp = (caddr_t)DB_PCI_REG_ADDR_TYPE1(
2029*7656SSherry.Moore@Sun.COM pci_addr->c_busnum,
2030*7656SSherry.Moore@Sun.COM pci_addr->c_devnum,
2031*7656SSherry.Moore@Sun.COM pci_addr->c_funcnum,
2032*7656SSherry.Moore@Sun.COM offset);
20330Sstevel@tonic-gate db_pvt->access_mode |= DB_PCI_CONF_CYCLE_TYPE1;
20340Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip,
2035*7656SSherry.Moore@Sun.COM "access mode type 1\n");
20360Sstevel@tonic-gate }
20370Sstevel@tonic-gate DB_DEBUG4(DB_PCI_MAP, dip, "addrp<%x,%x,%x> = %lx\n",
2038*7656SSherry.Moore@Sun.COM pci_addr->c_busnum, pci_addr->c_devnum,
2039*7656SSherry.Moore@Sun.COM pci_addr->c_funcnum, *addrp);
20400Sstevel@tonic-gate
20410Sstevel@tonic-gate return (DDI_SUCCESS);
20420Sstevel@tonic-gate
20430Sstevel@tonic-gate default :
20440Sstevel@tonic-gate DB_DEBUG1(DB_PCI_MAP, dip, "DDI other %x\n",
2045*7656SSherry.Moore@Sun.COM mp->map_type);
20460Sstevel@tonic-gate break;
20470Sstevel@tonic-gate }
20480Sstevel@tonic-gate DB_DEBUG0(DB_PCI_MAP, dip, "exit\n");
20490Sstevel@tonic-gate
20500Sstevel@tonic-gate pdip = (dev_info_t *)DEVI(dip)->devi_parent;
20510Sstevel@tonic-gate return ((DEVI(pdip)->devi_ops->devo_bus_ops->bus_map)
2052*7656SSherry.Moore@Sun.COM (pdip, rdip, mp, offset, len, addrp));
20530Sstevel@tonic-gate }
20540Sstevel@tonic-gate
20550Sstevel@tonic-gate #ifdef DB_DEBUG
20560Sstevel@tonic-gate char *db_ctlop_name[] = {
20570Sstevel@tonic-gate "DDI_CTLOPS_DMAPMAPC",
20580Sstevel@tonic-gate "DDI_CTLOPS_INITCHILD",
20590Sstevel@tonic-gate "DDI_CTLOPS_UNINITCHILD",
20600Sstevel@tonic-gate "DDI_CTLOPS_REPORTDEV",
20610Sstevel@tonic-gate "DDI_CTLOPS_REPORTINT",
20620Sstevel@tonic-gate "DDI_CTLOPS_REGSIZE",
20630Sstevel@tonic-gate "DDI_CTLOPS_NREGS",
2064693Sgovinda "DDI_CTLOPS_RESERVED0",
20650Sstevel@tonic-gate "DDI_CTLOPS_SIDDEV",
20660Sstevel@tonic-gate "DDI_CTLOPS_SLAVEONLY",
20670Sstevel@tonic-gate "DDI_CTLOPS_AFFINITY",
20680Sstevel@tonic-gate "DDI_CTLOPS_IOMIN",
20690Sstevel@tonic-gate "DDI_CTLOPS_PTOB",
20700Sstevel@tonic-gate "DDI_CTLOPS_BTOP",
20710Sstevel@tonic-gate "DDI_CTLOPS_BTOPR",
20720Sstevel@tonic-gate "DDI_CTLOPS_RESERVED1",
20730Sstevel@tonic-gate "DDI_CTLOPS_RESERVED2",
20740Sstevel@tonic-gate "DDI_CTLOPS_RESERVED3",
2075693Sgovinda "DDI_CTLOPS_RESERVED4",
2076693Sgovinda "DDI_CTLOPS_RESERVED5",
20770Sstevel@tonic-gate "DDI_CTLOPS_DVMAPAGESIZE",
20780Sstevel@tonic-gate "DDI_CTLOPS_POWER",
20790Sstevel@tonic-gate "DDI_CTLOPS_ATTACH",
20800Sstevel@tonic-gate "DDI_CTLOPS_DETACH",
20810Sstevel@tonic-gate "DDI_CTLOPS_POKE",
20820Sstevel@tonic-gate "DDI_CTLOPS_PEEK"
20830Sstevel@tonic-gate };
20840Sstevel@tonic-gate #endif
20850Sstevel@tonic-gate
20860Sstevel@tonic-gate static int
db_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)20870Sstevel@tonic-gate db_ctlops(dev_info_t *dip, dev_info_t *rdip,
20880Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result)
20890Sstevel@tonic-gate {
20900Sstevel@tonic-gate
20910Sstevel@tonic-gate if ((ctlop >= DDI_CTLOPS_DMAPMAPC) &&
2092*7656SSherry.Moore@Sun.COM (ctlop <= DDI_CTLOPS_DETACH)) {
20930Sstevel@tonic-gate DB_DEBUG1(DB_CTLOPS, dip, "ctlop=%s\n", db_ctlop_name[ctlop]);
20940Sstevel@tonic-gate } else {
20950Sstevel@tonic-gate DB_DEBUG1(DB_CTLOPS, dip, "ctlop=%d\n", ctlop);
20960Sstevel@tonic-gate }
20970Sstevel@tonic-gate
20980Sstevel@tonic-gate switch (ctlop) {
20990Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV :
21000Sstevel@tonic-gate if (rdip == (dev_info_t *)0)
21010Sstevel@tonic-gate return (DDI_FAILURE);
21020Sstevel@tonic-gate cmn_err(CE_CONT, "?PCI-device: %s@%s, %s#%d\n",
21030Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip),
21040Sstevel@tonic-gate ddi_driver_name(rdip),
21050Sstevel@tonic-gate ddi_get_instance(rdip));
21060Sstevel@tonic-gate return (DDI_SUCCESS);
21070Sstevel@tonic-gate
21080Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD :
21090Sstevel@tonic-gate return (db_initchild((dev_info_t *)arg));
21100Sstevel@tonic-gate
21110Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD :
21120Sstevel@tonic-gate db_uninitchild((dev_info_t *)arg);
21130Sstevel@tonic-gate return (DDI_SUCCESS);
21140Sstevel@tonic-gate
21150Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV :
21160Sstevel@tonic-gate return (DDI_SUCCESS);
21170Sstevel@tonic-gate
21180Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE :
21190Sstevel@tonic-gate case DDI_CTLOPS_NREGS :
21200Sstevel@tonic-gate if (rdip == (dev_info_t *)0)
21210Sstevel@tonic-gate return (DDI_FAILURE);
21220Sstevel@tonic-gate /* fall through */
21230Sstevel@tonic-gate
21240Sstevel@tonic-gate default :
21250Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result));
21260Sstevel@tonic-gate }
21270Sstevel@tonic-gate
21280Sstevel@tonic-gate }
21290Sstevel@tonic-gate
21300Sstevel@tonic-gate static dev_info_t *
db_get_my_childs_dip(dev_info_t * dip,dev_info_t * rdip)21310Sstevel@tonic-gate db_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip)
21320Sstevel@tonic-gate {
21330Sstevel@tonic-gate dev_info_t *cdip = rdip;
21340Sstevel@tonic-gate
21350Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip))
21360Sstevel@tonic-gate ;
21370Sstevel@tonic-gate
21380Sstevel@tonic-gate return (cdip);
21390Sstevel@tonic-gate }
21400Sstevel@tonic-gate
21410Sstevel@tonic-gate static int
db_intr_ops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)21420Sstevel@tonic-gate db_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
21430Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result)
21440Sstevel@tonic-gate {
21450Sstevel@tonic-gate dev_info_t *cdip = rdip;
21460Sstevel@tonic-gate pci_regspec_t *pci_rp;
21470Sstevel@tonic-gate int reglen, len;
21480Sstevel@tonic-gate uint32_t d, intr;
21490Sstevel@tonic-gate
21500Sstevel@tonic-gate DB_DEBUG1(DB_INTR_OPS, dip, "intr_op=%d\n", intr_op);
21510Sstevel@tonic-gate
21524395Sgovinda if ((intr_op == DDI_INTROP_SUPPORTED_TYPES) ||
21534395Sgovinda (hdlp->ih_type != DDI_INTR_TYPE_FIXED))
21540Sstevel@tonic-gate goto done;
21550Sstevel@tonic-gate
21560Sstevel@tonic-gate /*
21570Sstevel@tonic-gate * If the interrupt-map property is defined at this
21580Sstevel@tonic-gate * node, it will have performed the interrupt
21590Sstevel@tonic-gate * translation as part of the property, so no
21600Sstevel@tonic-gate * rotation needs to be done.
21610Sstevel@tonic-gate */
21620Sstevel@tonic-gate
21630Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
21640Sstevel@tonic-gate "interrupt-map", &len) == DDI_PROP_SUCCESS)
21650Sstevel@tonic-gate goto done;
21660Sstevel@tonic-gate
21670Sstevel@tonic-gate cdip = db_get_my_childs_dip(dip, rdip);
21680Sstevel@tonic-gate
21690Sstevel@tonic-gate /*
21700Sstevel@tonic-gate * Use the devices reg property to determine it's
21710Sstevel@tonic-gate * PCI bus number and device number.
21720Sstevel@tonic-gate */
2173506Scth if (ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS,
21740Sstevel@tonic-gate "reg", (caddr_t)&pci_rp, ®len) != DDI_SUCCESS)
21750Sstevel@tonic-gate return (DDI_FAILURE);
21760Sstevel@tonic-gate
2177693Sgovinda intr = hdlp->ih_vector;
21780Sstevel@tonic-gate
21790Sstevel@tonic-gate /* Spin the interrupt */
21800Sstevel@tonic-gate d = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi);
21810Sstevel@tonic-gate
21820Sstevel@tonic-gate if ((intr >= PCI_INTA) && (intr <= PCI_INTD))
2183693Sgovinda hdlp->ih_vector = ((intr - 1 + (d % 4)) % 4 + 1);
21840Sstevel@tonic-gate else
21850Sstevel@tonic-gate cmn_err(CE_WARN, "%s#%d: %s: PCI intr=%x out of range",
21860Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip),
21870Sstevel@tonic-gate ddi_driver_name(dip), intr);
21880Sstevel@tonic-gate
21890Sstevel@tonic-gate DB_DEBUG3(DB_INTR_OPS, dip, "intr=%d, d=%d, is_intr=%d\n",
2190693Sgovinda intr, d, hdlp->ih_vector);
21910Sstevel@tonic-gate
21920Sstevel@tonic-gate kmem_free(pci_rp, reglen);
21930Sstevel@tonic-gate
21940Sstevel@tonic-gate done:
21950Sstevel@tonic-gate /* Pass up the request to our parent. */
21960Sstevel@tonic-gate return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result));
21970Sstevel@tonic-gate }
21980Sstevel@tonic-gate
21990Sstevel@tonic-gate static int
db_name_child(dev_info_t * child,char * name,int namelen)22000Sstevel@tonic-gate db_name_child(dev_info_t *child, char *name, int namelen)
22010Sstevel@tonic-gate {
22020Sstevel@tonic-gate uint_t n, slot, func;
22030Sstevel@tonic-gate pci_regspec_t *pci_rp;
22040Sstevel@tonic-gate
22050Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) {
22060Sstevel@tonic-gate char **unit_addr;
22070Sstevel@tonic-gate
22080Sstevel@tonic-gate /* name .conf nodes by "unit-address" property" */
22090Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child,
22100Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) !=
22110Sstevel@tonic-gate DDI_PROP_SUCCESS) {
22120Sstevel@tonic-gate cmn_err(CE_WARN, "cannot name node from %s.conf",
22130Sstevel@tonic-gate ddi_driver_name(child));
22140Sstevel@tonic-gate return (DDI_FAILURE);
22150Sstevel@tonic-gate }
22160Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) {
22170Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf"
22180Sstevel@tonic-gate " not well-formed", ddi_driver_name(child));
22190Sstevel@tonic-gate ddi_prop_free(unit_addr);
22200Sstevel@tonic-gate return (DDI_FAILURE);
22210Sstevel@tonic-gate }
22220Sstevel@tonic-gate
22230Sstevel@tonic-gate (void) snprintf(name, namelen, "%s", *unit_addr);
22240Sstevel@tonic-gate ddi_prop_free(unit_addr);
22250Sstevel@tonic-gate return (DDI_SUCCESS);
22260Sstevel@tonic-gate }
22270Sstevel@tonic-gate
22280Sstevel@tonic-gate /* name hardware nodes by "reg" property */
22290Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, 0, "reg",
22300Sstevel@tonic-gate (int **)&pci_rp, &n) != DDI_SUCCESS)
22310Sstevel@tonic-gate return (DDI_FAILURE);
22320Sstevel@tonic-gate
22330Sstevel@tonic-gate /* get the device identifications */
22340Sstevel@tonic-gate slot = PCI_REG_DEV_G(pci_rp->pci_phys_hi);
22350Sstevel@tonic-gate func = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
22360Sstevel@tonic-gate
22370Sstevel@tonic-gate if (func != 0)
22380Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", slot, func);
22390Sstevel@tonic-gate else
22400Sstevel@tonic-gate (void) snprintf(name, namelen, "%x", slot);
22410Sstevel@tonic-gate
22420Sstevel@tonic-gate ddi_prop_free(pci_rp);
22430Sstevel@tonic-gate return (DDI_SUCCESS);
22440Sstevel@tonic-gate }
22450Sstevel@tonic-gate
22460Sstevel@tonic-gate static int
db_initchild(dev_info_t * child)22470Sstevel@tonic-gate db_initchild(dev_info_t *child)
22480Sstevel@tonic-gate {
22490Sstevel@tonic-gate char name[MAXNAMELEN];
22500Sstevel@tonic-gate ddi_acc_handle_t config_handle;
22510Sstevel@tonic-gate ushort_t command_preserve, command;
22520Sstevel@tonic-gate uint_t n;
22530Sstevel@tonic-gate ushort_t bcr;
22540Sstevel@tonic-gate uchar_t header_type, min_gnt, latency_timer;
22550Sstevel@tonic-gate db_ctrl_t *dbp;
22560Sstevel@tonic-gate
22570Sstevel@tonic-gate if (db_name_child(child, name, MAXNAMELEN) != DDI_SUCCESS)
22580Sstevel@tonic-gate return (DDI_FAILURE);
22590Sstevel@tonic-gate
22600Sstevel@tonic-gate ddi_set_name_addr(child, name);
22610Sstevel@tonic-gate ddi_set_parent_data(child, NULL);
22620Sstevel@tonic-gate
22630Sstevel@tonic-gate /*
22640Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance
22650Sstevel@tonic-gate * properties to be merged into the real h/w device node.
22660Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F]
22670Sstevel@tonic-gate * where DD is the device id and F is the function.
22680Sstevel@tonic-gate */
22690Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) {
22700Sstevel@tonic-gate extern int pci_allow_pseudo_children;
22710Sstevel@tonic-gate
22720Sstevel@tonic-gate /*
22730Sstevel@tonic-gate * Try to merge the properties from this prototype
22740Sstevel@tonic-gate * node into real h/w nodes.
22750Sstevel@tonic-gate */
22760Sstevel@tonic-gate if (ndi_merge_node(child, db_name_child) == DDI_SUCCESS) {
22770Sstevel@tonic-gate /*
22780Sstevel@tonic-gate * Merged ok - return failure to remove the node.
22790Sstevel@tonic-gate */
22800Sstevel@tonic-gate return (DDI_FAILURE);
22810Sstevel@tonic-gate }
22820Sstevel@tonic-gate
22830Sstevel@tonic-gate /* workaround for ddivs to run under PCI */
22840Sstevel@tonic-gate if (pci_allow_pseudo_children) {
22850Sstevel@tonic-gate return (DDI_SUCCESS);
22860Sstevel@tonic-gate }
22870Sstevel@tonic-gate
22880Sstevel@tonic-gate /*
22890Sstevel@tonic-gate * The child was not merged into a h/w node,
22900Sstevel@tonic-gate * but there's not much we can do with it other
22910Sstevel@tonic-gate * than return failure to cause the node to be removed.
22920Sstevel@tonic-gate */
22930Sstevel@tonic-gate cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
22940Sstevel@tonic-gate ddi_driver_name(child), ddi_get_name_addr(child),
22950Sstevel@tonic-gate ddi_driver_name(child));
22960Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED);
22970Sstevel@tonic-gate }
22980Sstevel@tonic-gate
22990Sstevel@tonic-gate
23000Sstevel@tonic-gate if ((db_create_pci_prop(child) != DDI_SUCCESS) ||
23010Sstevel@tonic-gate (pci_config_setup(child, &config_handle) != DDI_SUCCESS)) {
23020Sstevel@tonic-gate db_uninitchild(child);
23030Sstevel@tonic-gate return (DDI_FAILURE);
23040Sstevel@tonic-gate }
23050Sstevel@tonic-gate
23060Sstevel@tonic-gate /*
23070Sstevel@tonic-gate * Determine the configuration header type.
23080Sstevel@tonic-gate */
23090Sstevel@tonic-gate header_type = pci_config_get8(config_handle, PCI_CONF_HEADER);
23100Sstevel@tonic-gate
23110Sstevel@tonic-gate /*
23120Sstevel@tonic-gate * Support for the "command-preserve" property.
23130Sstevel@tonic-gate */
23140Sstevel@tonic-gate command_preserve = ddi_prop_get_int(DDI_DEV_T_ANY, child,
2315*7656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "command-preserve", 0);
23160Sstevel@tonic-gate command = pci_config_get16(config_handle, PCI_CONF_COMM);
23170Sstevel@tonic-gate command &= (command_preserve | PCI_COMM_BACK2BACK_ENAB);
23180Sstevel@tonic-gate command |= (db_command_default & ~command_preserve);
23190Sstevel@tonic-gate pci_config_put16(config_handle, PCI_CONF_COMM, command);
23200Sstevel@tonic-gate
23210Sstevel@tonic-gate DB_DEBUG2(DB_INITCHILD, ddi_get_parent(child),
2322*7656SSherry.Moore@Sun.COM "initializing device vend=%x, devid=%x\n",
2323*7656SSherry.Moore@Sun.COM pci_config_get16(config_handle, PCI_CONF_VENID),
2324*7656SSherry.Moore@Sun.COM pci_config_get16(config_handle, PCI_CONF_DEVID));
23250Sstevel@tonic-gate /*
23260Sstevel@tonic-gate * If the device has a bus control register then program it
23270Sstevel@tonic-gate * based on the settings in the command register.
23280Sstevel@tonic-gate */
23290Sstevel@tonic-gate if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) {
23300Sstevel@tonic-gate bcr = pci_config_get8(config_handle, PCI_BCNF_BCNTRL);
23310Sstevel@tonic-gate if (db_command_default & PCI_COMM_PARITY_DETECT)
23320Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_PARITY_ENABLE;
23330Sstevel@tonic-gate if (db_command_default & PCI_COMM_SERR_ENABLE)
23340Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_SERR_ENABLE;
23350Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_MAST_AB_MODE;
23360Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_BCNTRL, bcr);
23370Sstevel@tonic-gate }
23380Sstevel@tonic-gate
23390Sstevel@tonic-gate dbp = (db_ctrl_t *)ddi_get_soft_state(db_state,
23400Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(child)));
23410Sstevel@tonic-gate
23420Sstevel@tonic-gate /*
23430Sstevel@tonic-gate * Initialize cache-line-size configuration register if needed.
23440Sstevel@tonic-gate */
23450Sstevel@tonic-gate if (db_set_cache_line_size_register &&
23460Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
2347*7656SSherry.Moore@Sun.COM "cache-line-size", 0) == 0) {
23480Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_CACHE_LINESZ,
2349*7656SSherry.Moore@Sun.COM dbp->cache_line_size);
23500Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ);
23510Sstevel@tonic-gate if (n != 0) {
23520Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child,
2353*7656SSherry.Moore@Sun.COM "cache-line-size", n);
23540Sstevel@tonic-gate }
23550Sstevel@tonic-gate DB_DEBUG1(DB_INITCHILD, ddi_get_parent(child),
2356*7656SSherry.Moore@Sun.COM "\nChild Device Cache Size %x\n", dbp->cache_line_size);
23570Sstevel@tonic-gate }
23580Sstevel@tonic-gate
23590Sstevel@tonic-gate /*
23600Sstevel@tonic-gate * Initialize latency timer configuration registers if needed.
23610Sstevel@tonic-gate */
23620Sstevel@tonic-gate if (db_set_latency_timer_register &&
23630Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
2364*7656SSherry.Moore@Sun.COM "latency-timer", 0) == 0) {
23650Sstevel@tonic-gate
23660Sstevel@tonic-gate if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) {
23670Sstevel@tonic-gate latency_timer = dbp->p_latency_timer;
23680Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_LATENCY_TIMER,
2369*7656SSherry.Moore@Sun.COM dbp->latency_timer);
23700Sstevel@tonic-gate } else {
23710Sstevel@tonic-gate min_gnt = pci_config_get8(config_handle,
2372*7656SSherry.Moore@Sun.COM PCI_CONF_MIN_G);
23730Sstevel@tonic-gate latency_timer = min_gnt * 8;
23740Sstevel@tonic-gate }
23750Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_LATENCY_TIMER,
2376*7656SSherry.Moore@Sun.COM latency_timer);
23770Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER);
23780Sstevel@tonic-gate if (n != 0) {
23790Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child,
2380*7656SSherry.Moore@Sun.COM "latency-timer", n);
23810Sstevel@tonic-gate }
23820Sstevel@tonic-gate DB_DEBUG1(DB_INITCHILD, ddi_get_parent(child),
2383*7656SSherry.Moore@Sun.COM "\nChild Device latency %x\n", latency_timer);
23840Sstevel@tonic-gate }
23850Sstevel@tonic-gate
23860Sstevel@tonic-gate pci_config_teardown(&config_handle);
23870Sstevel@tonic-gate return (DDI_SUCCESS);
23880Sstevel@tonic-gate }
23890Sstevel@tonic-gate
23900Sstevel@tonic-gate static void
db_uninitchild(dev_info_t * dip)23910Sstevel@tonic-gate db_uninitchild(dev_info_t *dip)
23920Sstevel@tonic-gate {
23930Sstevel@tonic-gate ddi_set_name_addr(dip, NULL);
23940Sstevel@tonic-gate
23950Sstevel@tonic-gate /*
23960Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form
23970Sstevel@tonic-gate */
23980Sstevel@tonic-gate impl_rem_dev_props(dip);
23990Sstevel@tonic-gate }
24000Sstevel@tonic-gate
24010Sstevel@tonic-gate static int
db_create_pci_prop(dev_info_t * child)24020Sstevel@tonic-gate db_create_pci_prop(dev_info_t *child)
24030Sstevel@tonic-gate {
24040Sstevel@tonic-gate pci_regspec_t *pci_rp;
24050Sstevel@tonic-gate int length;
24060Sstevel@tonic-gate int value;
24070Sstevel@tonic-gate
24080Sstevel@tonic-gate /* get child "reg" property */
2409506Scth value = ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_CANSLEEP,
2410*7656SSherry.Moore@Sun.COM "reg", (caddr_t)&pci_rp, &length);
24110Sstevel@tonic-gate if (value != DDI_SUCCESS)
24120Sstevel@tonic-gate return (value);
24130Sstevel@tonic-gate
24140Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, child, "reg",
2415*7656SSherry.Moore@Sun.COM (uchar_t *)pci_rp, length);
24160Sstevel@tonic-gate
24170Sstevel@tonic-gate /*
24180Sstevel@tonic-gate * free the memory allocated by ddi_getlongprop ().
24190Sstevel@tonic-gate */
24200Sstevel@tonic-gate kmem_free(pci_rp, length);
24210Sstevel@tonic-gate
24220Sstevel@tonic-gate /*
24230Sstevel@tonic-gate * No need to create any 1275 properties here, because either
24240Sstevel@tonic-gate * the OBP creates them or the hotplug framework creates it
24250Sstevel@tonic-gate * during a hotplug operation. So lets return here.
24260Sstevel@tonic-gate */
24270Sstevel@tonic-gate return (DDI_SUCCESS);
24280Sstevel@tonic-gate }
24290Sstevel@tonic-gate
24300Sstevel@tonic-gate /*
24310Sstevel@tonic-gate * db_save_config_regs
24320Sstevel@tonic-gate *
24330Sstevel@tonic-gate * This routine saves the state of the configuration registers of all
24340Sstevel@tonic-gate * immediate child nodes.
24350Sstevel@tonic-gate *
24360Sstevel@tonic-gate * used by: db_detach() on suspends
24370Sstevel@tonic-gate *
24380Sstevel@tonic-gate * return value: DDI_SUCCESS: ALl children state saved.
24390Sstevel@tonic-gate * DDI_FAILURE: Child device state could not be saved.
24400Sstevel@tonic-gate */
24410Sstevel@tonic-gate static int
db_save_config_regs(db_ctrl_t * dbp)24420Sstevel@tonic-gate db_save_config_regs(db_ctrl_t *dbp)
24430Sstevel@tonic-gate {
24440Sstevel@tonic-gate int i;
24450Sstevel@tonic-gate dev_info_t *dip;
24460Sstevel@tonic-gate ddi_acc_handle_t config_handle;
24470Sstevel@tonic-gate db_cfg_state_t *statep;
24480Sstevel@tonic-gate
24490Sstevel@tonic-gate for (i = 0, dip = ddi_get_child(dbp->dip); dip != NULL;
2450*7656SSherry.Moore@Sun.COM dip = ddi_get_next_sibling(dip)) {
24511333Scth if (i_ddi_devi_attached(dip))
24520Sstevel@tonic-gate i++;
24530Sstevel@tonic-gate }
24540Sstevel@tonic-gate dbp->config_state_index = i;
24550Sstevel@tonic-gate
24560Sstevel@tonic-gate if (!i) {
24570Sstevel@tonic-gate /* no children */
24580Sstevel@tonic-gate dbp->db_config_state_p = NULL;
24590Sstevel@tonic-gate return (DDI_SUCCESS);
24600Sstevel@tonic-gate }
24610Sstevel@tonic-gate
24620Sstevel@tonic-gate /* i now equals the total number of child devices */
24630Sstevel@tonic-gate dbp->db_config_state_p =
2464*7656SSherry.Moore@Sun.COM kmem_zalloc(i * sizeof (db_cfg_state_t), KM_NOSLEEP);
24650Sstevel@tonic-gate if (!dbp->db_config_state_p) {
24660Sstevel@tonic-gate cmn_err(CE_WARN,
2467*7656SSherry.Moore@Sun.COM "%s#%d: No memory to save state for child %s#%d\n",
2468*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2469*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip),
2470*7656SSherry.Moore@Sun.COM ddi_get_name(dip), ddi_get_instance(dip));
24710Sstevel@tonic-gate return (DDI_FAILURE);
24720Sstevel@tonic-gate }
24730Sstevel@tonic-gate
24740Sstevel@tonic-gate for (statep = dbp->db_config_state_p,
2475*7656SSherry.Moore@Sun.COM dip = ddi_get_child(dbp->dip);
2476*7656SSherry.Moore@Sun.COM dip != NULL;
2477*7656SSherry.Moore@Sun.COM dip = ddi_get_next_sibling(dip)) {
24780Sstevel@tonic-gate
24791333Scth if (!i_ddi_devi_attached(dip))
24800Sstevel@tonic-gate continue;
24810Sstevel@tonic-gate
24820Sstevel@tonic-gate if (pci_config_setup(dip, &config_handle) != DDI_SUCCESS) {
24830Sstevel@tonic-gate cmn_err(CE_WARN,
2484*7656SSherry.Moore@Sun.COM "%s#%d: can't config space for %s#%d",
2485*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2486*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip),
2487*7656SSherry.Moore@Sun.COM ddi_driver_name(dip),
2488*7656SSherry.Moore@Sun.COM ddi_get_instance(dip));
24890Sstevel@tonic-gate continue;
24900Sstevel@tonic-gate }
24910Sstevel@tonic-gate
24920Sstevel@tonic-gate statep->dip = dip;
24930Sstevel@tonic-gate statep->command =
2494*7656SSherry.Moore@Sun.COM pci_config_get16(config_handle, PCI_CONF_COMM);
24950Sstevel@tonic-gate statep->header_type =
2496*7656SSherry.Moore@Sun.COM pci_config_get8(config_handle, PCI_CONF_HEADER);
24970Sstevel@tonic-gate if ((statep->header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE)
24980Sstevel@tonic-gate statep->bridge_control =
24990Sstevel@tonic-gate pci_config_get16(config_handle, PCI_BCNF_BCNTRL);
25000Sstevel@tonic-gate statep->cache_line_size =
2501*7656SSherry.Moore@Sun.COM pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ);
25020Sstevel@tonic-gate statep->latency_timer =
2503*7656SSherry.Moore@Sun.COM pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER);
25040Sstevel@tonic-gate if ((statep->header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE)
25050Sstevel@tonic-gate statep->sec_latency_timer =
25060Sstevel@tonic-gate pci_config_get8(config_handle,
2507*7656SSherry.Moore@Sun.COM PCI_BCNF_LATENCY_TIMER);
25080Sstevel@tonic-gate pci_config_teardown(&config_handle);
25090Sstevel@tonic-gate statep++;
25100Sstevel@tonic-gate }
25110Sstevel@tonic-gate return (DDI_SUCCESS);
25120Sstevel@tonic-gate }
25130Sstevel@tonic-gate
25140Sstevel@tonic-gate
25150Sstevel@tonic-gate /*
25160Sstevel@tonic-gate * db_restore_config_regs
25170Sstevel@tonic-gate *
25180Sstevel@tonic-gate * This routine restores the state of the configuration registers of
25190Sstevel@tonic-gate * all immediate child nodes.
25200Sstevel@tonic-gate *
25210Sstevel@tonic-gate * used by: db_attach() on resume
25220Sstevel@tonic-gate *
25230Sstevel@tonic-gate * return value: none
25240Sstevel@tonic-gate */
25250Sstevel@tonic-gate static int
db_restore_config_regs(db_ctrl_t * dbp)25260Sstevel@tonic-gate db_restore_config_regs(db_ctrl_t *dbp)
25270Sstevel@tonic-gate {
25280Sstevel@tonic-gate int i;
25290Sstevel@tonic-gate dev_info_t *dip;
25300Sstevel@tonic-gate ddi_acc_handle_t config_handle;
25310Sstevel@tonic-gate db_cfg_state_t *statep = dbp->db_config_state_p;
25320Sstevel@tonic-gate
25330Sstevel@tonic-gate for (i = 0; i < dbp->config_state_index; i++, statep++) {
25340Sstevel@tonic-gate dip = statep->dip;
25350Sstevel@tonic-gate if (!dip) {
25360Sstevel@tonic-gate cmn_err(CE_WARN,
2537*7656SSherry.Moore@Sun.COM "%s#%d: skipping bad dev info (index %d)",
2538*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2539*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip), i);
25400Sstevel@tonic-gate continue;
25410Sstevel@tonic-gate }
25420Sstevel@tonic-gate if (pci_config_setup(dip, &config_handle) != DDI_SUCCESS) {
25430Sstevel@tonic-gate cmn_err(CE_WARN,
2544*7656SSherry.Moore@Sun.COM "%s#%d: can't config space for %s#%d",
2545*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2546*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip),
2547*7656SSherry.Moore@Sun.COM ddi_driver_name(dip),
2548*7656SSherry.Moore@Sun.COM ddi_get_instance(dip));
25490Sstevel@tonic-gate continue;
25500Sstevel@tonic-gate }
25510Sstevel@tonic-gate pci_config_put16(config_handle, PCI_CONF_COMM, statep->command);
25520Sstevel@tonic-gate if ((statep->header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE)
25530Sstevel@tonic-gate pci_config_put16(config_handle, PCI_BCNF_BCNTRL,
2554*7656SSherry.Moore@Sun.COM statep->bridge_control);
25550Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_CACHE_LINESZ,
2556*7656SSherry.Moore@Sun.COM statep->cache_line_size);
25570Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_LATENCY_TIMER,
2558*7656SSherry.Moore@Sun.COM statep->latency_timer);
25590Sstevel@tonic-gate if ((statep->header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE)
25600Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_LATENCY_TIMER,
2561*7656SSherry.Moore@Sun.COM statep->sec_latency_timer);
25620Sstevel@tonic-gate pci_config_teardown(&config_handle);
25630Sstevel@tonic-gate }
25640Sstevel@tonic-gate
25650Sstevel@tonic-gate kmem_free(dbp->db_config_state_p,
2566*7656SSherry.Moore@Sun.COM dbp->config_state_index * sizeof (db_cfg_state_t));
25670Sstevel@tonic-gate dbp->db_config_state_p = NULL;
25680Sstevel@tonic-gate dbp->config_state_index = 0;
25690Sstevel@tonic-gate
25700Sstevel@tonic-gate return (DDI_SUCCESS);
25710Sstevel@tonic-gate }
25720Sstevel@tonic-gate
25730Sstevel@tonic-gate /* put a type 0/1 address on the bus */
25740Sstevel@tonic-gate static void
db_put_reg_conf_addr(db_acc_pvt_t * db_pvt,uint32_t conf_addr)25750Sstevel@tonic-gate db_put_reg_conf_addr(db_acc_pvt_t *db_pvt, uint32_t conf_addr)
25760Sstevel@tonic-gate {
25770Sstevel@tonic-gate if (db_pvt->access_mode & DB_PCI_CONF_CYCLE_TYPE0)\
25780Sstevel@tonic-gate ddi_put32(db_pvt->handle, db_pvt->addr, (uint32_t)\
2579*7656SSherry.Moore@Sun.COM DB_PCI_CONF_CYCLE_TYPE0_ADDR((conf_addr)));\
25800Sstevel@tonic-gate else /* type 1 cycle */\
25810Sstevel@tonic-gate ddi_put32(db_pvt->handle, db_pvt->addr, (uint32_t)\
2582*7656SSherry.Moore@Sun.COM DB_PCI_CONF_CYCLE_TYPE1_ADDR((conf_addr)));
25830Sstevel@tonic-gate }
25840Sstevel@tonic-gate
25850Sstevel@tonic-gate /* Get 8bits data off the 32bit data */
25860Sstevel@tonic-gate static uint8_t
db_get_data8(uint32_t addr,uint32_t data)25870Sstevel@tonic-gate db_get_data8(uint32_t addr, uint32_t data)
25880Sstevel@tonic-gate {
25890Sstevel@tonic-gate return (((data) >> (((addr) & 3) * 8)) & 0xff);
25900Sstevel@tonic-gate }
25910Sstevel@tonic-gate
25920Sstevel@tonic-gate /* Get 16bits data off the 32bit data */
25930Sstevel@tonic-gate static uint16_t
db_get_data16(uint32_t addr,uint32_t data)25940Sstevel@tonic-gate db_get_data16(uint32_t addr, uint32_t data)
25950Sstevel@tonic-gate {
25960Sstevel@tonic-gate return (((data) >> (((addr) & 3) * 8)) & 0xffff);
25970Sstevel@tonic-gate }
25980Sstevel@tonic-gate
25990Sstevel@tonic-gate /* merge 8bit data into the 32bit data */
26000Sstevel@tonic-gate static uint32_t
db_put_data8(uint32_t addr,uint32_t rdata,uint8_t wdata)26010Sstevel@tonic-gate db_put_data8(uint32_t addr, uint32_t rdata, uint8_t wdata)
26020Sstevel@tonic-gate {
26030Sstevel@tonic-gate return ((rdata & (~((0xff << ((((addr) & 3) * 8))) & 0xffffffff))) |
2604*7656SSherry.Moore@Sun.COM (((wdata) & 0xff)<<((((addr) & 3))*8)));
26050Sstevel@tonic-gate }
26060Sstevel@tonic-gate
26070Sstevel@tonic-gate /* merge 16bit data into the 32bit data */
26080Sstevel@tonic-gate static uint32_t
db_put_data16(uint32_t addr,uint32_t rdata,uint16_t wdata)26090Sstevel@tonic-gate db_put_data16(uint32_t addr, uint32_t rdata, uint16_t wdata)
26100Sstevel@tonic-gate {
26110Sstevel@tonic-gate return ((rdata & (~((0xffff << ((((addr) & 3) * 8))) & 0xffffffff))) |
2612*7656SSherry.Moore@Sun.COM (((wdata) & 0xffff) << ((((addr) & 3))*8)));
26130Sstevel@tonic-gate }
26140Sstevel@tonic-gate
26150Sstevel@tonic-gate
26160Sstevel@tonic-gate /*
26170Sstevel@tonic-gate * For the next set of PCI configuration IO calls, we need
26180Sstevel@tonic-gate * to make sure we own the bus before generating the config cycles,
26190Sstevel@tonic-gate * using the drawbridge's semaphore method.
26200Sstevel@tonic-gate */
26210Sstevel@tonic-gate
26220Sstevel@tonic-gate /*
26230Sstevel@tonic-gate * Function to read 8 bit data off the PCI configuration space behind
26240Sstevel@tonic-gate * the 21554's host interface.
26250Sstevel@tonic-gate */
26260Sstevel@tonic-gate static uint8_t
db_ddi_get8(ddi_acc_impl_t * handle,uint8_t * addr)26270Sstevel@tonic-gate db_ddi_get8(ddi_acc_impl_t *handle, uint8_t *addr)
26280Sstevel@tonic-gate {
26290Sstevel@tonic-gate uint32_t data;
26300Sstevel@tonic-gate
26310Sstevel@tonic-gate data = db_ddi_get32(handle, (uint32_t *)addr);
2632946Smathue return (db_get_data8((uint32_t)(uintptr_t)addr, data));
26330Sstevel@tonic-gate }
26340Sstevel@tonic-gate
26350Sstevel@tonic-gate /*
26360Sstevel@tonic-gate * Function to read 16 bit data off the PCI configuration space behind
26370Sstevel@tonic-gate * the 21554's host interface.
26380Sstevel@tonic-gate */
26390Sstevel@tonic-gate static uint16_t
db_ddi_get16(ddi_acc_impl_t * handle,uint16_t * addr)26400Sstevel@tonic-gate db_ddi_get16(ddi_acc_impl_t *handle, uint16_t *addr)
26410Sstevel@tonic-gate {
26420Sstevel@tonic-gate uint32_t data;
26430Sstevel@tonic-gate
26440Sstevel@tonic-gate data = db_ddi_get32(handle, (uint32_t *)addr);
2645946Smathue return (db_get_data16((uint32_t)(uintptr_t)addr, data));
26460Sstevel@tonic-gate }
26470Sstevel@tonic-gate
26480Sstevel@tonic-gate /*
26490Sstevel@tonic-gate * Function to read 32 bit data off the PCI configuration space behind
26500Sstevel@tonic-gate * the 21554's host interface.
26510Sstevel@tonic-gate */
26520Sstevel@tonic-gate static uint32_t
db_ddi_get32(ddi_acc_impl_t * handle,uint32_t * addr)26530Sstevel@tonic-gate db_ddi_get32(ddi_acc_impl_t *handle, uint32_t *addr)
26540Sstevel@tonic-gate {
2655*7656SSherry.Moore@Sun.COM db_acc_pvt_t *db_pvt = (db_acc_pvt_t *)
2656*7656SSherry.Moore@Sun.COM handle->ahi_common.ah_bus_private;
2657*7656SSherry.Moore@Sun.COM uint32_t wait_count = 0;
2658*7656SSherry.Moore@Sun.COM uint32_t data;
26590Sstevel@tonic-gate db_ctrl_t *dbp;
26600Sstevel@tonic-gate
26610Sstevel@tonic-gate dbp = db_pvt->dbp;
26620Sstevel@tonic-gate
26630Sstevel@tonic-gate mutex_enter(&dbp->db_busown);
26640Sstevel@tonic-gate
26650Sstevel@tonic-gate if (db_use_config_own_bit) {
26660Sstevel@tonic-gate /*
26670Sstevel@tonic-gate * check if (upstream/downstream)configuration address own
26680Sstevel@tonic-gate * bit set. With this set, we cannot proceed.
26690Sstevel@tonic-gate */
26700Sstevel@tonic-gate while (((ddi_get8(db_pvt->handle, db_pvt->bus_own)) &
2671*7656SSherry.Moore@Sun.COM db_pvt->mask) == db_pvt->mask) {
26720Sstevel@tonic-gate #ifdef DEBUG
26730Sstevel@tonic-gate if (dbp->db_pci_max_wait_count < wait_count)
26740Sstevel@tonic-gate dbp->db_pci_max_wait_count = wait_count;
26750Sstevel@tonic-gate #endif
26760Sstevel@tonic-gate drv_usecwait(db_pci_own_wait);
26770Sstevel@tonic-gate if (++wait_count == db_pci_max_wait) {
26780Sstevel@tonic-gate /*
26790Sstevel@tonic-gate * the man page for pci_config_* routines do
26800Sstevel@tonic-gate * Not specify any error condition values.
26810Sstevel@tonic-gate */
26820Sstevel@tonic-gate cmn_err(CE_WARN,
2683*7656SSherry.Moore@Sun.COM "%s#%d: pci config bus own error",
2684*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2685*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
26860Sstevel@tonic-gate dbp->db_pci_err_count++;
26870Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
26880Sstevel@tonic-gate return ((uint32_t)DB_CONF_FAILURE);
26890Sstevel@tonic-gate }
26900Sstevel@tonic-gate }
26910Sstevel@tonic-gate wait_count = 0;
26920Sstevel@tonic-gate }
26930Sstevel@tonic-gate
2694946Smathue db_put_reg_conf_addr(db_pvt, (uint32_t)(uintptr_t)addr);
26950Sstevel@tonic-gate data = ddi_get32(db_pvt->handle, (uint32_t *)db_pvt->data);
26960Sstevel@tonic-gate
26970Sstevel@tonic-gate if (db_use_config_own_bit) {
26980Sstevel@tonic-gate while (((ddi_get8(db_pvt->handle, db_pvt->bus_release)) &
2699*7656SSherry.Moore@Sun.COM db_pvt->mask) == db_pvt->mask) {
27000Sstevel@tonic-gate #ifdef DEBUG
27010Sstevel@tonic-gate if (dbp->db_pci_max_wait_count < wait_count)
27020Sstevel@tonic-gate dbp->db_pci_max_wait_count = wait_count;
27030Sstevel@tonic-gate #endif
27040Sstevel@tonic-gate drv_usecwait(db_pci_release_wait);
27050Sstevel@tonic-gate if (++wait_count == db_pci_max_wait) {
27060Sstevel@tonic-gate /*
27070Sstevel@tonic-gate * the man page for pci_config_* routines do
27080Sstevel@tonic-gate * not specify any error condition values.
27090Sstevel@tonic-gate */
27100Sstevel@tonic-gate cmn_err(CE_WARN,
2711*7656SSherry.Moore@Sun.COM "%s#%d: pci config bus release error",
2712*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2713*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
27140Sstevel@tonic-gate dbp->db_pci_err_count++;
27150Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
27160Sstevel@tonic-gate return ((uint32_t)DB_CONF_FAILURE);
27170Sstevel@tonic-gate }
27180Sstevel@tonic-gate data = ddi_get32(db_pvt->handle,
2719*7656SSherry.Moore@Sun.COM (uint32_t *)db_pvt->data);
27200Sstevel@tonic-gate }
27210Sstevel@tonic-gate }
27220Sstevel@tonic-gate
27230Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
27240Sstevel@tonic-gate
27250Sstevel@tonic-gate return (data);
27260Sstevel@tonic-gate }
27270Sstevel@tonic-gate
27280Sstevel@tonic-gate /*
27290Sstevel@tonic-gate * Function to read 64 bit data off the PCI configuration space behind
27300Sstevel@tonic-gate * the 21554's host interface.
27310Sstevel@tonic-gate */
27320Sstevel@tonic-gate static uint64_t
db_ddi_get64(ddi_acc_impl_t * handle,uint64_t * addr)27330Sstevel@tonic-gate db_ddi_get64(ddi_acc_impl_t *handle, uint64_t *addr)
27340Sstevel@tonic-gate {
27350Sstevel@tonic-gate uint64_t udata, ldata;
27360Sstevel@tonic-gate
27370Sstevel@tonic-gate ldata = (uint32_t)db_ddi_get32(handle, (uint32_t *)addr);
27380Sstevel@tonic-gate udata = (uint32_t)db_ddi_get32(handle, (uint32_t *)addr + 1);
27390Sstevel@tonic-gate return (ldata | (udata << 32));
27400Sstevel@tonic-gate }
27410Sstevel@tonic-gate
27420Sstevel@tonic-gate /*
27430Sstevel@tonic-gate * Function to write 8 bit data into the PCI configuration space behind
27440Sstevel@tonic-gate * the 21554's host interface.
27450Sstevel@tonic-gate */
27460Sstevel@tonic-gate static void
db_ddi_put8(ddi_acc_impl_t * handle,uint8_t * addr,uint8_t data)27470Sstevel@tonic-gate db_ddi_put8(ddi_acc_impl_t *handle, uint8_t *addr, uint8_t data)
27480Sstevel@tonic-gate {
27490Sstevel@tonic-gate uint32_t rdata;
27500Sstevel@tonic-gate
27510Sstevel@tonic-gate rdata = db_ddi_get32(handle, (uint32_t *)addr);
27520Sstevel@tonic-gate db_ddi_put32(handle, (uint32_t *)addr,
2753*7656SSherry.Moore@Sun.COM db_put_data8((uint32_t)(uintptr_t)addr, rdata, data));
27540Sstevel@tonic-gate }
27550Sstevel@tonic-gate
27560Sstevel@tonic-gate /*
27570Sstevel@tonic-gate * Function to write 16 bit data into the PCI configuration space behind
27580Sstevel@tonic-gate * the 21554's host interface.
27590Sstevel@tonic-gate */
27600Sstevel@tonic-gate static void
db_ddi_put16(ddi_acc_impl_t * handle,uint16_t * addr,uint16_t data)27610Sstevel@tonic-gate db_ddi_put16(ddi_acc_impl_t *handle, uint16_t *addr, uint16_t data)
27620Sstevel@tonic-gate {
27630Sstevel@tonic-gate uint32_t rdata;
27640Sstevel@tonic-gate
27650Sstevel@tonic-gate rdata = db_ddi_get32(handle, (uint32_t *)addr);
27660Sstevel@tonic-gate db_ddi_put32(handle, (uint32_t *)addr,
2767*7656SSherry.Moore@Sun.COM db_put_data16((uint32_t)(uintptr_t)addr, rdata, data));
27680Sstevel@tonic-gate }
27690Sstevel@tonic-gate
27700Sstevel@tonic-gate /*
27710Sstevel@tonic-gate * Function to write 32 bit data into the PCI configuration space behind
27720Sstevel@tonic-gate * the 21554's host interface.
27730Sstevel@tonic-gate */
27740Sstevel@tonic-gate static void
db_ddi_put32(ddi_acc_impl_t * handle,uint32_t * addr,uint32_t data)27750Sstevel@tonic-gate db_ddi_put32(ddi_acc_impl_t *handle, uint32_t *addr, uint32_t data)
27760Sstevel@tonic-gate {
2777*7656SSherry.Moore@Sun.COM db_acc_pvt_t *db_pvt = (db_acc_pvt_t *)
2778*7656SSherry.Moore@Sun.COM handle->ahi_common.ah_bus_private;
27790Sstevel@tonic-gate db_ctrl_t *dbp;
2780*7656SSherry.Moore@Sun.COM uint32_t wait_count = 0;
27810Sstevel@tonic-gate
27820Sstevel@tonic-gate dbp = db_pvt->dbp;
27830Sstevel@tonic-gate
27840Sstevel@tonic-gate mutex_enter(&dbp->db_busown);
27850Sstevel@tonic-gate
27860Sstevel@tonic-gate if (db_use_config_own_bit) {
27870Sstevel@tonic-gate /*
27880Sstevel@tonic-gate * check if (upstream/downstream)configuration address own
27890Sstevel@tonic-gate * bit set. with this set, we cannot proceed.
27900Sstevel@tonic-gate */
27910Sstevel@tonic-gate while (((ddi_get8(db_pvt->handle, db_pvt->bus_own)) &
2792*7656SSherry.Moore@Sun.COM db_pvt->mask) == db_pvt->mask) {
27930Sstevel@tonic-gate #ifdef DEBUG
27940Sstevel@tonic-gate if (dbp->db_pci_max_wait_count < wait_count)
27950Sstevel@tonic-gate dbp->db_pci_max_wait_count = wait_count;
27960Sstevel@tonic-gate #endif
27970Sstevel@tonic-gate drv_usecwait(db_pci_own_wait);
27980Sstevel@tonic-gate if (++wait_count == db_pci_max_wait) {
27990Sstevel@tonic-gate /*
28000Sstevel@tonic-gate * Since the return value is void here,
28010Sstevel@tonic-gate * we may need to print a message, as this
28020Sstevel@tonic-gate * could be a serious situation.
28030Sstevel@tonic-gate */
28040Sstevel@tonic-gate cmn_err(CE_WARN,
2805*7656SSherry.Moore@Sun.COM "%s#%d: pci config bus own error",
2806*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2807*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
28080Sstevel@tonic-gate dbp->db_pci_err_count++;
28090Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
28100Sstevel@tonic-gate return;
28110Sstevel@tonic-gate }
28120Sstevel@tonic-gate }
28130Sstevel@tonic-gate wait_count = 0;
28140Sstevel@tonic-gate }
28150Sstevel@tonic-gate
2816946Smathue db_put_reg_conf_addr(db_pvt, (uint32_t)(uintptr_t)addr);
28170Sstevel@tonic-gate ddi_put32(db_pvt->handle, (uint32_t *)db_pvt->data, data);
28180Sstevel@tonic-gate
28190Sstevel@tonic-gate if (db_use_config_own_bit) {
28200Sstevel@tonic-gate while (((ddi_get8(db_pvt->handle, db_pvt->bus_release)) &
2821*7656SSherry.Moore@Sun.COM db_pvt->mask) == db_pvt->mask) {
28220Sstevel@tonic-gate #ifdef DEBUG
28230Sstevel@tonic-gate if (dbp->db_pci_max_wait_count < wait_count)
28240Sstevel@tonic-gate dbp->db_pci_max_wait_count = wait_count;
28250Sstevel@tonic-gate #endif
28260Sstevel@tonic-gate drv_usecwait(db_pci_release_wait);
28270Sstevel@tonic-gate if (++wait_count == db_pci_max_wait) {
28280Sstevel@tonic-gate /*
28290Sstevel@tonic-gate * the man page for pci_config_* routines do
28300Sstevel@tonic-gate * Not specify any error condition values.
28310Sstevel@tonic-gate */
28320Sstevel@tonic-gate cmn_err(CE_WARN,
2833*7656SSherry.Moore@Sun.COM "%s#%d: pci config bus release error",
2834*7656SSherry.Moore@Sun.COM ddi_driver_name(dbp->dip),
2835*7656SSherry.Moore@Sun.COM ddi_get_instance(dbp->dip));
28360Sstevel@tonic-gate dbp->db_pci_err_count++;
28370Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
28380Sstevel@tonic-gate return;
28390Sstevel@tonic-gate }
28400Sstevel@tonic-gate ddi_put32(db_pvt->handle, (uint32_t *)db_pvt->data,
2841*7656SSherry.Moore@Sun.COM data);
28420Sstevel@tonic-gate }
28430Sstevel@tonic-gate }
28440Sstevel@tonic-gate
28450Sstevel@tonic-gate mutex_exit(&dbp->db_busown);
28460Sstevel@tonic-gate }
28470Sstevel@tonic-gate
28480Sstevel@tonic-gate /*
28490Sstevel@tonic-gate * Function to write 64 bit data into the PCI configuration space behind
28500Sstevel@tonic-gate * the 21554's host interface.
28510Sstevel@tonic-gate */
28520Sstevel@tonic-gate static void
db_ddi_put64(ddi_acc_impl_t * handle,uint64_t * addr,uint64_t data)28530Sstevel@tonic-gate db_ddi_put64(ddi_acc_impl_t *handle, uint64_t *addr, uint64_t data)
28540Sstevel@tonic-gate {
28550Sstevel@tonic-gate db_ddi_put32(handle, (uint32_t *)addr, (uint32_t)(data & 0xffffffff));
28560Sstevel@tonic-gate db_ddi_put32(handle, (uint32_t *)addr + 1, (uint32_t)(data >> 32));
28570Sstevel@tonic-gate }
28580Sstevel@tonic-gate
28590Sstevel@tonic-gate /*
28600Sstevel@tonic-gate * Function to rep read 8 bit data off the PCI configuration space behind
28610Sstevel@tonic-gate * the 21554's host interface.
28620Sstevel@tonic-gate */
28630Sstevel@tonic-gate static void
db_ddi_rep_get8(ddi_acc_impl_t * handle,uint8_t * host_addr,uint8_t * dev_addr,size_t repcount,uint_t flags)28640Sstevel@tonic-gate db_ddi_rep_get8(ddi_acc_impl_t *handle, uint8_t *host_addr,
28650Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags)
28660Sstevel@tonic-gate {
28670Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
28680Sstevel@tonic-gate for (; repcount; repcount--)
28690Sstevel@tonic-gate *host_addr++ = db_ddi_get8(handle, dev_addr++);
28700Sstevel@tonic-gate else
28710Sstevel@tonic-gate for (; repcount; repcount--)
28720Sstevel@tonic-gate *host_addr++ = db_ddi_get8(handle, dev_addr);
28730Sstevel@tonic-gate }
28740Sstevel@tonic-gate
28750Sstevel@tonic-gate /*
28760Sstevel@tonic-gate * Function to rep read 16 bit data off the PCI configuration space behind
28770Sstevel@tonic-gate * the 21554's host interface.
28780Sstevel@tonic-gate */
28790Sstevel@tonic-gate static void
db_ddi_rep_get16(ddi_acc_impl_t * handle,uint16_t * host_addr,uint16_t * dev_addr,size_t repcount,uint_t flags)28800Sstevel@tonic-gate db_ddi_rep_get16(ddi_acc_impl_t *handle, uint16_t *host_addr,
28810Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags)
28820Sstevel@tonic-gate {
28830Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
28840Sstevel@tonic-gate for (; repcount; repcount--)
28850Sstevel@tonic-gate *host_addr++ = db_ddi_get16(handle, dev_addr++);
28860Sstevel@tonic-gate else
28870Sstevel@tonic-gate for (; repcount; repcount--)
28880Sstevel@tonic-gate *host_addr++ = db_ddi_get16(handle, dev_addr);
28890Sstevel@tonic-gate }
28900Sstevel@tonic-gate
28910Sstevel@tonic-gate /*
28920Sstevel@tonic-gate * Function to rep read 32 bit data off the PCI configuration space behind
28930Sstevel@tonic-gate * the 21554's host interface.
28940Sstevel@tonic-gate */
28950Sstevel@tonic-gate static void
db_ddi_rep_get32(ddi_acc_impl_t * handle,uint32_t * host_addr,uint32_t * dev_addr,size_t repcount,uint_t flags)28960Sstevel@tonic-gate db_ddi_rep_get32(ddi_acc_impl_t *handle, uint32_t *host_addr,
28970Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags)
28980Sstevel@tonic-gate {
28990Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29000Sstevel@tonic-gate for (; repcount; repcount--)
29010Sstevel@tonic-gate *host_addr++ = db_ddi_get32(handle, dev_addr++);
29020Sstevel@tonic-gate else
29030Sstevel@tonic-gate for (; repcount; repcount--)
29040Sstevel@tonic-gate *host_addr++ = db_ddi_get32(handle, dev_addr);
29050Sstevel@tonic-gate }
29060Sstevel@tonic-gate
29070Sstevel@tonic-gate /*
29080Sstevel@tonic-gate * Function to rep read 64 bit data off the PCI configuration space behind
29090Sstevel@tonic-gate * the 21554's host interface.
29100Sstevel@tonic-gate */
29110Sstevel@tonic-gate static void
db_ddi_rep_get64(ddi_acc_impl_t * handle,uint64_t * host_addr,uint64_t * dev_addr,size_t repcount,uint_t flags)29120Sstevel@tonic-gate db_ddi_rep_get64(ddi_acc_impl_t *handle, uint64_t *host_addr,
29130Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags)
29140Sstevel@tonic-gate {
29150Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29160Sstevel@tonic-gate for (; repcount; repcount--)
29170Sstevel@tonic-gate *host_addr++ = db_ddi_get64(handle, dev_addr++);
29180Sstevel@tonic-gate else
29190Sstevel@tonic-gate for (; repcount; repcount--)
29200Sstevel@tonic-gate *host_addr++ = db_ddi_get64(handle, dev_addr);
29210Sstevel@tonic-gate }
29220Sstevel@tonic-gate
29230Sstevel@tonic-gate /*
29240Sstevel@tonic-gate * Function to rep write 8 bit data into the PCI configuration space behind
29250Sstevel@tonic-gate * the 21554's host interface.
29260Sstevel@tonic-gate */
29270Sstevel@tonic-gate static void
db_ddi_rep_put8(ddi_acc_impl_t * handle,uint8_t * host_addr,uint8_t * dev_addr,size_t repcount,uint_t flags)29280Sstevel@tonic-gate db_ddi_rep_put8(ddi_acc_impl_t *handle, uint8_t *host_addr,
29290Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags)
29300Sstevel@tonic-gate {
29310Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29320Sstevel@tonic-gate for (; repcount; repcount--)
29330Sstevel@tonic-gate db_ddi_put8(handle, dev_addr++, *host_addr++);
29340Sstevel@tonic-gate else
29350Sstevel@tonic-gate for (; repcount; repcount--)
29360Sstevel@tonic-gate db_ddi_put8(handle, dev_addr, *host_addr++);
29370Sstevel@tonic-gate }
29380Sstevel@tonic-gate
29390Sstevel@tonic-gate /*
29400Sstevel@tonic-gate * Function to rep write 16 bit data into the PCI configuration space behind
29410Sstevel@tonic-gate * the 21554's host interface.
29420Sstevel@tonic-gate */
29430Sstevel@tonic-gate static void
db_ddi_rep_put16(ddi_acc_impl_t * handle,uint16_t * host_addr,uint16_t * dev_addr,size_t repcount,uint_t flags)29440Sstevel@tonic-gate db_ddi_rep_put16(ddi_acc_impl_t *handle, uint16_t *host_addr,
29450Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags)
29460Sstevel@tonic-gate {
29470Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29480Sstevel@tonic-gate for (; repcount; repcount--)
29490Sstevel@tonic-gate db_ddi_put16(handle, dev_addr++, *host_addr++);
29500Sstevel@tonic-gate else
29510Sstevel@tonic-gate for (; repcount; repcount--)
29520Sstevel@tonic-gate db_ddi_put16(handle, dev_addr, *host_addr++);
29530Sstevel@tonic-gate }
29540Sstevel@tonic-gate
29550Sstevel@tonic-gate /*
29560Sstevel@tonic-gate * Function to rep write 32 bit data into the PCI configuration space behind
29570Sstevel@tonic-gate * the 21554's host interface.
29580Sstevel@tonic-gate */
29590Sstevel@tonic-gate static void
db_ddi_rep_put32(ddi_acc_impl_t * handle,uint32_t * host_addr,uint32_t * dev_addr,size_t repcount,uint_t flags)29600Sstevel@tonic-gate db_ddi_rep_put32(ddi_acc_impl_t *handle, uint32_t *host_addr,
29610Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags)
29620Sstevel@tonic-gate {
29630Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29640Sstevel@tonic-gate for (; repcount; repcount--)
29650Sstevel@tonic-gate db_ddi_put32(handle, dev_addr++, *host_addr++);
29660Sstevel@tonic-gate else
29670Sstevel@tonic-gate for (; repcount; repcount--)
29680Sstevel@tonic-gate db_ddi_put32(handle, dev_addr, *host_addr++);
29690Sstevel@tonic-gate }
29700Sstevel@tonic-gate
29710Sstevel@tonic-gate /*
29720Sstevel@tonic-gate * Function to rep write 64 bit data into the PCI configuration space behind
29730Sstevel@tonic-gate * the 21554's host interface.
29740Sstevel@tonic-gate */
29750Sstevel@tonic-gate static void
db_ddi_rep_put64(ddi_acc_impl_t * handle,uint64_t * host_addr,uint64_t * dev_addr,size_t repcount,uint_t flags)29760Sstevel@tonic-gate db_ddi_rep_put64(ddi_acc_impl_t *handle, uint64_t *host_addr,
29770Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags)
29780Sstevel@tonic-gate {
29790Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
29800Sstevel@tonic-gate for (; repcount; repcount--)
29810Sstevel@tonic-gate db_ddi_put64(handle, dev_addr++, *host_addr++);
29820Sstevel@tonic-gate else
29830Sstevel@tonic-gate for (; repcount; repcount--)
29840Sstevel@tonic-gate db_ddi_put64(handle, dev_addr, *host_addr++);
29850Sstevel@tonic-gate }
29860Sstevel@tonic-gate
29870Sstevel@tonic-gate #ifdef DEBUG
29880Sstevel@tonic-gate
29890Sstevel@tonic-gate static void
db_debug(uint64_t func_id,dev_info_t * dip,char * fmt,uintptr_t a1,uintptr_t a2,uintptr_t a3,uintptr_t a4,uintptr_t a5)29900Sstevel@tonic-gate db_debug(uint64_t func_id, dev_info_t *dip, char *fmt,
29910Sstevel@tonic-gate uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
29920Sstevel@tonic-gate {
29930Sstevel@tonic-gate char *s = NULL;
29940Sstevel@tonic-gate uint_t dip_no_disp = 0;
29950Sstevel@tonic-gate
29960Sstevel@tonic-gate if (func_id & DB_DONT_DISPLAY_DIP) {
29970Sstevel@tonic-gate dip_no_disp = 1;
29980Sstevel@tonic-gate }
29990Sstevel@tonic-gate if (db_debug_funcs & func_id) {
30000Sstevel@tonic-gate switch (func_id) {
30010Sstevel@tonic-gate case DB_INIT: s = "_init"; break;
30020Sstevel@tonic-gate case DB_FINI: s = "_fini"; break;
30030Sstevel@tonic-gate case DB_INFO: s = "_info"; break;
30040Sstevel@tonic-gate case DB_GETINFO: s = "getinfo"; break;
30050Sstevel@tonic-gate case DB_ATTACH: s = "attach"; break;
30060Sstevel@tonic-gate case DB_DETACH: s = "detach"; break;
30070Sstevel@tonic-gate case DB_CTLOPS: s = "ctlops"; break;
30080Sstevel@tonic-gate case DB_INITCHILD: s = "initchild"; break;
30090Sstevel@tonic-gate case DB_REMOVECHILD: s = "removechild"; break;
30100Sstevel@tonic-gate case DB_INTR_OPS: s = "intr_ops"; break;
30110Sstevel@tonic-gate case DB_PCI_MAP: s = "map"; break;
30120Sstevel@tonic-gate case DB_SAVE_CONF_REGS: s = "save_conf_regs"; break;
30130Sstevel@tonic-gate case DB_REST_CONF_REGS: s = "restore_conf_regs"; break;
30140Sstevel@tonic-gate case DB_INTR: s = "intr"; break;
30150Sstevel@tonic-gate case DB_OPEN: s = "open"; break;
30160Sstevel@tonic-gate case DB_CLOSE: s = "close"; break;
30170Sstevel@tonic-gate case DB_IOCTL: s = "ioctl"; break;
30180Sstevel@tonic-gate case DB_DVMA: s = "set_dvma_range"; break;
30190Sstevel@tonic-gate
30200Sstevel@tonic-gate default: s = "PCI debug unknown"; break;
30210Sstevel@tonic-gate }
30220Sstevel@tonic-gate
30230Sstevel@tonic-gate if (s && !dip_no_disp) {
30240Sstevel@tonic-gate prom_printf("%s(%d): %s: ", ddi_driver_name(dip),
30250Sstevel@tonic-gate ddi_get_instance(dip), s);
30260Sstevel@tonic-gate }
30270Sstevel@tonic-gate prom_printf(fmt, a1, a2, a3, a4, a5);
30280Sstevel@tonic-gate }
30290Sstevel@tonic-gate }
30300Sstevel@tonic-gate #endif
30310Sstevel@tonic-gate
db_prop_op(dev_t dev,dev_info_t * dip,ddi_prop_op_t prop_op,int flags,char * name,caddr_t valuep,int * lengthp)30320Sstevel@tonic-gate static int db_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
30330Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp)
30340Sstevel@tonic-gate {
30350Sstevel@tonic-gate minor_t minor = getminor(dev);
30360Sstevel@tonic-gate int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
30370Sstevel@tonic-gate
30380Sstevel@tonic-gate db_ctrl_t *dbp = (db_ctrl_t *)ddi_get_soft_state(db_state, instance);
30390Sstevel@tonic-gate
30400Sstevel@tonic-gate
30410Sstevel@tonic-gate if (dbp == NULL)
30420Sstevel@tonic-gate return (ENXIO);
30430Sstevel@tonic-gate
30440Sstevel@tonic-gate if (dbp->dev_state & DB_SECONDARY_NEXUS)
30450Sstevel@tonic-gate return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip,
30460Sstevel@tonic-gate prop_op, flags, name, valuep, lengthp));
30470Sstevel@tonic-gate
30480Sstevel@tonic-gate return (ddi_prop_op(dev, dip, prop_op, flags, name, valuep, lengthp));
30490Sstevel@tonic-gate }
30500Sstevel@tonic-gate
30510Sstevel@tonic-gate /*
30520Sstevel@tonic-gate * Initialize our FMA resources
30530Sstevel@tonic-gate */
30540Sstevel@tonic-gate static void
db_fm_init(db_ctrl_t * db_p)30550Sstevel@tonic-gate db_fm_init(db_ctrl_t *db_p)
30560Sstevel@tonic-gate {
30570Sstevel@tonic-gate db_p->fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
3058*7656SSherry.Moore@Sun.COM DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE;
30590Sstevel@tonic-gate
30600Sstevel@tonic-gate /*
30610Sstevel@tonic-gate * Request our capability level and get our parents capability
30620Sstevel@tonic-gate * and ibc.
30630Sstevel@tonic-gate */
30640Sstevel@tonic-gate ddi_fm_init(db_p->dip, &db_p->fm_cap, &db_p->fm_ibc);
30650Sstevel@tonic-gate ASSERT((db_p->fm_cap & DDI_FM_EREPORT_CAPABLE) &&
30660Sstevel@tonic-gate (db_p->fm_cap & DDI_FM_ERRCB_CAPABLE));
30670Sstevel@tonic-gate
30680Sstevel@tonic-gate pci_ereport_setup(db_p->dip);
30690Sstevel@tonic-gate
30700Sstevel@tonic-gate /*
30710Sstevel@tonic-gate * Register error callback with our parent.
30720Sstevel@tonic-gate */
30730Sstevel@tonic-gate ddi_fm_handler_register(db_p->dip, db_err_callback, NULL);
30740Sstevel@tonic-gate }
30750Sstevel@tonic-gate
30760Sstevel@tonic-gate /*
30770Sstevel@tonic-gate * Breakdown our FMA resources
30780Sstevel@tonic-gate */
30790Sstevel@tonic-gate static void
db_fm_fini(db_ctrl_t * db_p)30800Sstevel@tonic-gate db_fm_fini(db_ctrl_t *db_p)
30810Sstevel@tonic-gate {
30820Sstevel@tonic-gate /*
30830Sstevel@tonic-gate * Clean up allocated fm structures
30840Sstevel@tonic-gate */
30850Sstevel@tonic-gate ddi_fm_handler_unregister(db_p->dip);
30860Sstevel@tonic-gate pci_ereport_teardown(db_p->dip);
30870Sstevel@tonic-gate ddi_fm_fini(db_p->dip);
30880Sstevel@tonic-gate }
30890Sstevel@tonic-gate
30900Sstevel@tonic-gate /*
30910Sstevel@tonic-gate * Initialize FMA resources for children devices. Called when
30920Sstevel@tonic-gate * child calls ddi_fm_init().
30930Sstevel@tonic-gate */
30940Sstevel@tonic-gate /*ARGSUSED*/
30950Sstevel@tonic-gate static int
db_fm_init_child(dev_info_t * dip,dev_info_t * tdip,int cap,ddi_iblock_cookie_t * ibc)30960Sstevel@tonic-gate db_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap,
30970Sstevel@tonic-gate ddi_iblock_cookie_t *ibc)
30980Sstevel@tonic-gate {
30990Sstevel@tonic-gate db_ctrl_t *db_p = (db_ctrl_t *)ddi_get_soft_state(db_state,
3100*7656SSherry.Moore@Sun.COM ddi_get_instance(dip));
31010Sstevel@tonic-gate *ibc = db_p->fm_ibc;
31020Sstevel@tonic-gate return (db_p->fm_cap);
31030Sstevel@tonic-gate }
31040Sstevel@tonic-gate
31050Sstevel@tonic-gate /*
31060Sstevel@tonic-gate * FMA registered error callback
31070Sstevel@tonic-gate */
31080Sstevel@tonic-gate static int
db_err_callback(dev_info_t * dip,ddi_fm_error_t * derr,const void * impl_data)31090Sstevel@tonic-gate db_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data)
31100Sstevel@tonic-gate {
31110Sstevel@tonic-gate ASSERT(impl_data == NULL);
31121865Sdilpreet pci_ereport_post(dip, derr, NULL);
31131865Sdilpreet return (derr->fme_status);
31140Sstevel@tonic-gate }
31150Sstevel@tonic-gate
31160Sstevel@tonic-gate static void
db_bus_enter(dev_info_t * dip,ddi_acc_handle_t handle)31170Sstevel@tonic-gate db_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle)
31180Sstevel@tonic-gate {
31190Sstevel@tonic-gate i_ndi_busop_access_enter(dip, handle);
31200Sstevel@tonic-gate }
31210Sstevel@tonic-gate
31220Sstevel@tonic-gate /* ARGSUSED */
31230Sstevel@tonic-gate static void
db_bus_exit(dev_info_t * dip,ddi_acc_handle_t handle)31240Sstevel@tonic-gate db_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle)
31250Sstevel@tonic-gate {
31260Sstevel@tonic-gate i_ndi_busop_access_exit(dip, handle);
31270Sstevel@tonic-gate }
3128