03831d35f7499c87d51205817c93e9a8d42c4baestevel * CDDL HEADER START
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The contents of this file are subject to the terms of the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Common Development and Distribution License (the "License").
03831d35f7499c87d51205817c93e9a8d42c4baestevel * You may not use this file except in compliance with the License.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
03831d35f7499c87d51205817c93e9a8d42c4baestevel * See the License for the specific language governing permissions
03831d35f7499c87d51205817c93e9a8d42c4baestevel * and limitations under the License.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * When distributing Covered Code, include this CDDL HEADER in each
03831d35f7499c87d51205817c93e9a8d42c4baestevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If applicable, add the following below this CDDL HEADER, with the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fields enclosed by brackets "[]" replaced with your own identifying
03831d35f7499c87d51205817c93e9a8d42c4baestevel * information: Portions Copyright [yyyy] [name of copyright owner]
03831d35f7499c87d51205817c93e9a8d42c4baestevel * CDDL HEADER END
07d06da50d310a325b457d6330165aebab1e0064Surya Prakki * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Use is subject to license terms.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Schizo/PCI Functions to the Safari Configurator
03831d35f7499c87d51205817c93e9a8d42c4baestevel#define GPTWO_DEBUG0(level, flag, s) if (gptwo_pci_debug >= level) \
03831d35f7499c87d51205817c93e9a8d42c4baestevel#define GPTWO_DEBUG1(level, flag, fmt, a1) if (gptwo_pci_debug >= level) \
03831d35f7499c87d51205817c93e9a8d42c4baestevel#define GPTWO_DEBUG2(level, flag, fmt, a1, a2) if (gptwo_pci_debug >= level) \
03831d35f7499c87d51205817c93e9a8d42c4baestevel debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), 0, 0, 0);
03831d35f7499c87d51205817c93e9a8d42c4baestevel debug(fmt, (uintptr_t)(a1), (uintptr_t)(a2), (uintptr_t)(a3), 0, 0);
03831d35f7499c87d51205817c93e9a8d42c4baestevelstatic void gptwo_find_nodes(dev_info_t *, int, gptwo_new_nodes_t *);
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Module linkage information for the kernel.
f500b19684bd0346ac05bec02a50af07f369da1aRichard Bean "gptwo->pci configurator",
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Create a resource map for the contigous memory allocated
03831d35f7499c87d51205817c93e9a8d42c4baestevel * at start-of-day in startup.c
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (ndi_ra_map_setup(ddi_root_node(), "gptwo-contigousmem")
03831d35f7499c87d51205817c93e9a8d42c4baestevel "Can not setup resource map - gptwo-contigousmem\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevel return (1);
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Put the allocated memory into the pool.
03831d35f7499c87d51205817c93e9a8d42c4baestevel (void) ndi_ra_free(ddi_root_node(), (uint64_t)efcode_vaddr,
03831d35f7499c87d51205817c93e9a8d42c4baestevel /* register devices with the configurator */
03831d35f7499c87d51205817c93e9a8d42c4baestevel gptwocfg_register_ops(SAFPTYPE_sPCI, gptwo_configure_pci,
03831d35f7499c87d51205817c93e9a8d42c4baestevel gptwocfg_register_ops(SAFPTYPE_cPCI, gptwo_configure_pci,
03831d35f7499c87d51205817c93e9a8d42c4baestevel gptwocfg_register_ops(SAFPTYPE_PCIX, gptwo_configure_pci,
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG1(1, CE_WARN, "gptwo_pci (PCI Functions) "
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG0(1, CE_WARN, "gptwo_pci (PCI Functions) "
03831d35f7499c87d51205817c93e9a8d42c4baestevel "has been loaded.\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevel/*ARGSUSED*/
03831d35f7499c87d51205817c93e9a8d42c4baestevelset_name_prop(dev_info_t *dip, void *arg, uint_t flags)
03831d35f7499c87d51205817c93e9a8d42c4baestevel/*ARGSUSED*/
03831d35f7499c87d51205817c93e9a8d42c4baestevelget_new_child(dev_info_t *rdip, void *arg, uint_t flags)
03831d35f7499c87d51205817c93e9a8d42c4baestevelgptwo_configure_pci(dev_info_t *ap, spcd_t *pcd, uint_t id)
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG2(1, CE_CONT, "gptwo_configure_pci: id=%x pcd=%lx\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel new_nodes = gptwocfg_allocate_node_list(IOBUS_PER_PORT);
03831d35f7499c87d51205817c93e9a8d42c4baestevel while (i) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Ideally, fcode would be run from the "sid_branch_create"
03831d35f7499c87d51205817c93e9a8d42c4baestevel * callback (that is the primary purpose of that callback).
03831d35f7499c87d51205817c93e9a8d42c4baestevel * However, the fcode interpreter was written with the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * assumption that the "new_child" was linked into the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * device tree. The callback is invoked with the devinfo node
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in the DS_PROTO state. More investigation is needed before
03831d35f7499c87d51205817c93e9a8d42c4baestevel * we can invoke the interpreter from the callback. For now,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * we create the "new_child" in the BOUND state, invoke the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fcode interpreter and then rebind the dip to use any
03831d35f7499c87d51205817c93e9a8d42c4baestevel * compatible properties created by fcode.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Prevent any changes to new_child
03831d35f7499c87d51205817c93e9a8d42c4baestevel * until we have bound it to the correct driver.
03831d35f7499c87d51205817c93e9a8d42c4baestevel "No nodes configured - "
03831d35f7499c87d51205817c93e9a8d42c4baestevel "removing new_nodes\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The platform DR interfaces created the dip in
03831d35f7499c87d51205817c93e9a8d42c4baestevel * bound state. Bring devinfo node down to linked
03831d35f7499c87d51205817c93e9a8d42c4baestevel * state and hold it there until compatible
03831d35f7499c87d51205817c93e9a8d42c4baestevel * properties are created.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Drop the busy-hold on parent before calling
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fcode_interpreter to prevent potential deadlocks
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Build the probe string from the PCD that will be passed
03831d35f7499c87d51205817c93e9a8d42c4baestevel * in to the interpreter as my-args. This will tell the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * fcode what pci devices to probe after the pci node has
03831d35f7499c87d51205817c93e9a8d42c4baestevel * been probed.
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG3(1, CE_CONT, "gptwo_configure_pci: args to "
03831d35f7499c87d51205817c93e9a8d42c4baestevel "interpreter ap=%lx new_child=%lx unit_address=%s\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel fco_handle = gp2_fc_ops_alloc_handle(ap, new_child, NULL, NULL,
03831d35f7499c87d51205817c93e9a8d42c4baestevel "gptwocfg: Calling Fcode Interpeter...\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevel error = fcode_interpreter(ap, &gp2_fc_ops, fco_handle);
03831d35f7499c87d51205817c93e9a8d42c4baestevel "gptwo_configure_pci: fcode_interpreter "
03831d35f7499c87d51205817c93e9a8d42c4baestevel cmn_err(CE_WARN, "gptwo_pci: Unable to probe pci leaf "
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Compatible properties (if any) have been created,
03831d35f7499c87d51205817c93e9a8d42c4baestevel * so bind driver.
03831d35f7499c87d51205817c93e9a8d42c4baestevel " new pci child at dip=0x%p\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If POST provided a frequency, the clock-frequency
03831d35f7499c87d51205817c93e9a8d42c4baestevel * property needs to be updated.
03831d35f7499c87d51205817c93e9a8d42c4baestevel * The upper byte is for leaf B and the lower
03831d35f7499c87d51205817c93e9a8d42c4baestevel * byte is for leaf A.
03831d35f7499c87d51205817c93e9a8d42c4baestevel "No nodes configured - removing new_nodes\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevel * If there is a handle, there may be resources
03831d35f7499c87d51205817c93e9a8d42c4baestevel * that need to be freed from when the
03831d35f7499c87d51205817c93e9a8d42c4baestevel * devices's fcode ran.
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG1(1, CE_CONT, "fco_handle=%lx\n", fco_handle);
03831d35f7499c87d51205817c93e9a8d42c4baestevelgptwo_find_nodes(dev_info_t *ap, int id, gptwo_new_nodes_t *new_nodes)
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG1(1, CE_CONT, "gptwo_find_nodes - id=%x\n", id);
03831d35f7499c87d51205817c93e9a8d42c4baestevel * We are walking child list of ap, so hold it busy
03831d35f7499c87d51205817c93e9a8d42c4baestevel "gptwo_find_nodes - "
03831d35f7499c87d51205817c93e9a8d42c4baestevel for (j = 0; j < IOBUS_PER_PORT; j++) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel * Branch rooted at saf-dev was
03831d35f7499c87d51205817c93e9a8d42c4baestevel * held earlier.
03831d35f7499c87d51205817c93e9a8d42c4baestevel "gptwo_find_nodes - "
03831d35f7499c87d51205817c93e9a8d42c4baestevel "No room in new_nodes\n");
03831d35f7499c87d51205817c93e9a8d42c4baestevelstatic char *
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG2(1, CE_CONT, "gptwo_get_probe_string - %p %x\n", pcd,
03831d35f7499c87d51205817c93e9a8d42c4baestevel for (i = 0; i < IOCARD_PER_BUS; i++) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel "card status %x %x\n",
03831d35f7499c87d51205817c93e9a8d42c4baestevel if (pcd->spcd_iocard_rsv[bus_number][i] == SPCD_RSV_PASS) {
03831d35f7499c87d51205817c93e9a8d42c4baestevel (void) sprintf(temp, "%sa", temp); /* Append a 'a' for leaf A */
03831d35f7499c87d51205817c93e9a8d42c4baestevel (void) sprintf(temp, "%sb", temp); /* Append a 'b' for leaf B */
03831d35f7499c87d51205817c93e9a8d42c4baestevel GPTWO_DEBUG1(1, CE_CONT, "gptwo_get_probe_string - Returning %s\n",