/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2010, Intel Corporation.
* All rights reserved.
*/
/*
* DR memory support routines.
*/
#include <sys/dditypes.h>
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
#include <sys/sysmacros.h>
#include <sys/machsystm.h>
#include <sys/mem_config.h>
#include <vm/seg_kmem.h>
extern struct memlist *phys_install;
/* TODO: push this reference below drmach line */
extern int kcage_on;
/*
* dr_mem_unit_t.sbm_flags
*/
/* helper macros */
static struct memlist *
{
static fn_t f = "dr_get_memlist";
/*
* Return cached memlist, if present.
* This memlist will be present following an
* unconfigure (a.k.a: detach) of this memunit.
* It should only be used in the case were a configure
* is bringing this memunit back in without going
* through the disconnect and connect states.
*/
PR_MEM("%s: found cached memlist\n", f);
} else {
/* attempt to construct a memlist using phys_install */
/* round down to slice base address */
/* get a copy of phys_install to edit */
/* trim lower irrelevant span */
if (mlist)
/* trim upper irrelevant span */
if (mlist) {
}
if (mlist) {
/* successfully built a memlist */
PR_MEM("%s: derived memlist from phys_install\n", f);
}
/* if no mlist yet, try platform layer */
if (!mlist) {
if (err) {
}
}
}
return (mlist);
}
/*ARGSUSED*/
void
{
}
void
{
static fn_t f = "dr_attach_mem";
PR_MEM("%s...\n", f);
if (err) {
return;
}
/* Skip memory with address above plat_dr_physmax or kpm_size */
if (kpm_size < dr_physmax)
int rv;
/*
* translate kphysm error and
* store in devlist error
*/
switch (rv) {
case KPHYSM_ERESOURCE:
rv = ESBD_NOMEM;
break;
case KPHYSM_EFAULT:
rv = ESBD_FAULT;
break;
default:
rv = ESBD_INTERNAL;
break;
}
if (rv == ESBD_INTERNAL) {
} else
break;
}
if (err) {
break;
}
}
/* back out if configure failed */
if (err)
sbd_err_clear(&err);
}
}
/*ARGSUSED*/
void
{
}
/*
* This routine acts as a wrapper for kphysm_del_span_query in order to
* support potential memory holes in a board's physical address space.
* It calls kphysm_del_span_query for each node in a memlist and accumulates
* the results in *mp.
*/
static int
{
int rv = 0;
mp->phys_pages = 0;
mp->nonrelocatable = 0;
mp->first_nonrelocatable = 0;
mp->last_nonrelocatable = 0;
return (rv);
}
/*
* NOTE: This routine is only partially smart about multiple
* mem-units. Need to make mem-status structure smart
* about them also.
*/
int
{
int m, mix;
static fn_t f = "dr_mem_status";
for (m = mix = 0; m < MAX_MEM_UNITS_PER_BOARD; m++) {
int rv;
continue;
/* present, but not fully initialized */
continue;
}
continue;
/* fetch platform status */
if (err) {
continue;
}
else
msp->ms_peer_is_target = 0;
char *minor;
/*
* b_dip doesn't have to be held for ddi_pathname()
* because the board struct (dr_board_t) will be
* destroyed before b_dip detaches.
*/
}
/*
* kphysm_del_span_query can report non-reloc pages = total
* pages for memory that is not yet configured
*/
if (mq.nonrelocatable &&
}
} else {
PR_MEM("%s: kphysm_del_span_query() = %d\n",
f, rv);
}
}
/*
* Check source unit state during copy-rename
*/
mix++;
dsp++;
}
return (mix);
}
/*ARGSUSED*/
int
{
int err_flag = 0;
int d;
static fn_t f = "dr_pre_attach_mem";
PR_MEM("%s...\n", f);
for (d = 0; d < devnum; d++) {
switch (state) {
case DR_STATE_UNCONFIGURED:
PR_MEM("%s: recovering from UNCONFIG for %s\n",
/* use memlist cached by dr_post_detach_mem_unit */
PR_MEM("%s: re-configuring cached memlist for %s:\n",
/* kphysm del handle should be have been freed */
/*FALLTHROUGH*/
case DR_STATE_CONNECTED:
PR_MEM("%s: reprogramming mem hardware on %s\n",
PR_MEM("%s: enabling %s\n",
if (err) {
err_flag = 1;
}
break;
default:
err_flag = 1;
break;
}
/* exit for loop if error encountered */
if (err_flag)
break;
}
return (err_flag ? -1 : 0);
}
/*ARGSUSED*/
int
{
int d;
static fn_t f = "dr_post_attach_mem";
PR_MEM("%s...\n", f);
for (d = 0; d < devnum; d++) {
/*
* Verify the memory really did successfully attach
* by checking for its existence in phys_install.
*/
PR_MEM("%s: %s memlist not in phys_install",
continue;
}
ml->ml_address,
if (err)
}
/*
* Destroy cached memlist, if any.
* There will be a cached memlist in sbm_mlist if
* this board is being configured directly after
* an unconfigure.
* To support this transition, dr_post_detach_mem
* left a copy of the last known memlist in sbm_mlist.
* This memlist could differ from any derived from
* hardware if while this memunit was last configured
* the system detected and deleted bad pages from
* phys_install. The location of those bad pages
* will be reflected in the cached memlist.
*/
}
}
return (0);
}
/*ARGSUSED*/
int
{
return (-1);
}
/*ARGSUSED*/
int
{
return (-1);
}
/*
* Successful return from this function will have the memory
* handle in bp->b_dev[..mem-unit...].sbm_memhandle allocated
* and waiting. This routine's job is to select the memory that
* actually has to be released (detached) which may not necessarily
* be the same memory node that came in in devlist[],
* i.e. a copy-rename is needed.
*/
/*ARGSUSED*/
int
{
return (-1);
}
/*ARGSUSED*/
void
{
}
/*ARGSUSED*/
int
{
return (-1);
}
/*ARGSUSED*/
int
{
return (-1);
}
void
{
} else {
}
/* delay transition until fully initialized */
}
static void
{
static fn_t f = "dr_init_mem_unit_data";
PR_MEM("%s...\n", f);
/* a little sanity checking */
return;
}
PR_MEM("%s: %s (basepfn = 0x%lx, npgs = %ld)\n",
}