/*
* 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.
*/
/*
* 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/spitregs.h>
#include <vm/seg_kmem.h>
#include <sys/platform_module.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);
}
typedef struct {
int error;
int done;
/*
* Memory has been logically removed by the time this routine is called.
*/
static void
{
}
/*
* When we reach here the memory being drained should have
* already been reserved in dr_pre_release_mem().
* Our only task here is to kick off the "drain" and wait
* for it to finish.
*/
void
{
int err;
static fn_t f = "dr_release_mem";
/* check that this memory unit has been reserved */
return;
}
(void *) &rms);
/* wait for completion or interrupt */
/* then there is a pending UNIX signal */
/* wait for completion */
}
}
/* get the result of the memory delete operation */
}
int e_code;
switch (err) {
case KPHYSM_ENOWORK:
break;
case KPHYSM_EHANDLE:
case KPHYSM_ESEQUENCE:
break;
case KPHYSM_ENOTVIABLE:
break;
case KPHYSM_EREFUSED:
break;
case KPHYSM_ENONRELOC:
break;
case KPHYSM_ECANCELLED:
break;
case KPHYSM_ERESOURCE:
break;
default:
"%s: unexpected kphysm error code %d,"
" id 0x%p",
break;
}
if (e_code != ESBD_NOERROR) {
}
}
}
void
{
static fn_t f = "dr_attach_mem";
PR_MEM("%s...\n", f);
if (err) {
return;
}
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);
}
}
static void
{
#ifdef DEBUG
#endif /* DEBUG */
static fn_t f = "dr_mem_ecache_scrub";
PR_MEM("%s: using proc %d, memlist...\n", f,
/* calculate the destination physical address */
"%s: address (0x%lx) not on "
"%s: size (0x%lx) not on "
/*LINTED*/
while (nbytes > 0) {
/* write 64 bits to dst_pa */
}
}
/*
* flush this cpu's ecache and take care to ensure
* that all of it's bus transactions have retired.
*/
#ifdef DEBUG
#endif /* DEBUG */
}
static int
{
static fn_t f = "dr_move_memory";
PR_MEM("%s: (INLINE) moving memory from %s to %s\n",
f,
/*
* create a memlist of spans to copy by removing
* the spans that have been deleted, if any, from
* the full source board memlist. s_mp->sbm_del_mlist
* will be NULL if there were no spans deleted from
* the source board.
*/
}
if (err) {
return (-1);
}
copytime = ddi_get_lbolt();
/* Quiesce the OS. */
if (dr_suspend(srhp)) {
" for copy-rename", f);
if (err) {
/*
* no error is expected since the program has
* not yet run.
*/
/* catch this in debug kernels */
ASSERT(0);
sbd_err_clear(&err);
}
/* suspend error reached via hp */
return (-1);
}
/*
* Rename memory for lgroup.
* Source and target board numbers are packaged in arg.
*/
{
}
/* Resume the OS. */
if (err)
PR_MEM("%s: copy-rename elapsed time = %ld ticks (%ld secs)\n",
}
/*
* If detaching node contains memory that is "non-permanent"
* then the memory adr's are simply cleared. If the memory
* is non-relocatable, then do a copy-rename.
*/
void
{
int rv = 0;
static fn_t f = "dr_detach_mem";
PR_MEM("%s...\n", f);
/* lookup target mem unit and target board structure, if any */
} else {
}
/* verify mem unit's state is UNREFERENCED */
if (state != DR_STATE_UNREFERENCED) {
return;
}
/* verify target mem unit's state is UNREFERENCED, if any */
if (state != DR_STATE_UNREFERENCED) {
return;
}
}
/*
* Scrub deleted memory. This will cause all cachelines
* referencing the memory to only be in the local cpu's
* ecache.
*/
if (s_mp->sbm_del_mlist)
}
}
/*
* we're done!
*/
/*
* Reprogram interconnect hardware and disable
* memory controllers for memory node that's going away.
*/
if (err) {
rv = -1;
}
} else {
PR_MEM("%s: %s memory COPY-RENAME (board %d -> %d)\n",
f,
if (rv != 0)
(void) dr_cancel_mem(s_mp);
}
if (rv == 0) {
if (err)
sbd_err_clear(&err);
}
}
#ifndef _STARFIRE
/*
* XXX workaround for certain lab configurations (see also starcat drmach.c)
* Temporary code to get around observed incorrect results from
* kphysm_del_span_query when the queried span contains address spans
* not occupied by memory in between spans that do have memory.
* This routine acts as a wrapper to kphysm_del_span_query. It builds
* a memlist from phys_install of spans that exist between base and
* base + npages, inclusively. Kphysm_del_span_query is called for each
* node in the memlist with the results accumulated in *mp.
*/
static int
{
int rv;
goto again;
}
}
mp->phys_pages = 0;
mp->nonrelocatable = 0;
mp->last_nonrelocatable = 0;
if (rv)
break;
if (mq.nonrelocatable != 0) {
}
}
if (mp->nonrelocatable == 0)
return (rv);
}
#endif /* _STARFIRE */
/*
* 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.
*/
}
else
/*
* Any pages above managed is "free",
* i.e. it's collected.
*/
} else {
/*
* If we're UNREFERENCED or UNCONFIGURED,
* then the number of detached pages is
* however many pages are on the board.
* I.e. detached = not in use by OS.
*/
/*
* changed to use cfgadm states
*
* was:
* case DR_STATE_UNREFERENCED:
* case DR_STATE_UNCONFIGURED:
*/
case SBD_STAT_UNCONFIGURED:
break;
default:
break;
}
}
/*
* 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);
}
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",
f,
/* 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);
}
int
{
int d;
static fn_t f = "dr_post_attach_mem";
PR_MEM("%s...\n", f);
for (d = 0; d < devnum; d++) {
continue;
}
/*
* 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.
*/
}
/*
* TODO: why is this call to dr_init_mem_unit_data here?
* this has been done at discovery or connect time, so this is
* probably redundant and unnecessary.
*/
}
return (0);
}
int
{
int d;
for (d = 0; d < devnum; d++) {
}
return (0);
}
int
{
int d, rv;
static fn_t f = "dr_post_detach_mem";
PR_MEM("%s...\n", f);
rv = 0;
for (d = 0; d < devnum; d++) {
if (dr_post_detach_mem_unit(mp))
rv = -1;
}
return (rv);
}
static void
{
static fn_t f = "dr_add_memory_spans";
PR_MEM("%s...", f);
#ifdef DEBUG
PR_MEM("%s:WARNING: memlist intersects with phys_install\n", f);
}
#endif
int rv;
ml->ml_address,
if (err)
" unexpected kphysm_add_memory_dynamic"
" return value %d;"
" basepfn=0x%lx, npages=%ld\n",
continue;
}
}
}
static int
{
/* old and new below refer to PAs before and after copy-rename */
int rv;
static fn_t f = "dr_post_detach_mem_unit";
PR_MEM("%s...\n", f);
/* s_mp->sbm_del_mlist could be NULL, meaning no deleted spans */
PR_MEM("%s: %s: deleted memlist (EMPTY maybe okay):\n",
/* sanity check */
PR_MEM("%s: target %s: deleted memlist:\n",
} else {
/* this is no target unit */
}
/*
* Verify the memory really did successfully detach
* by checking for its non-existence in phys_install.
*/
rv = 0;
}
}
if (rv) {
/* error: memlist still in phys_install */
}
/*
* clean mem unit state and bail out if an error has been recorded.
*/
rv = 0;
PR_MEM("%s: %s flags=%x", f,
rv = -1;
}
PR_MEM("%s: %s flags=%x", f,
rv = -1;
}
if (rv)
goto cleanup;
&s_new_basepa);
&t_new_basepa);
/*
* Construct copy list with original source addresses.
* Used to add back excess target mem.
*/
}
PR_MEM("%s: source copy list:\n:", f);
/*
* We had to swap mem-units, so update
* memlists accordingly with new base
* addresses.
*/
}
/*
* There is no need to explicitly rename the target delete
* memlist, because sbm_del_mlist and sbm_mlist always
*/
PR_MEM("%s: renamed target memlist and delete memlist:\n", f);
}
PR_MEM("%s: renamed source memlist:\n", f);
/*
* Keep track of dynamically added segments
* since they cannot be split if we need to delete
* excess source memory later for this board.
*/
if (t_mp->sbm_dyn_segs)
/*
* If the target memory range with the new target base PA
* extends beyond the usable slice, prevent any "target excess"
* calculate the new smaller size of the target board
* to be set as part of target cleanup. The base + npages
* must only include the range of memory up to the end of
* this slice. This will only be used after a category 4
* in dr_select_mem_target.
*/
}
t_new_smallsize == 0) {
/*
* Add back excess target memory.
* Subtract out the portion of the target memory
* node that was taken over by the source memory
* node.
*/
}
/*
* Update dynamically added segs
*/
t_mp->sbm_dyn_segs =
}
t_mp->sbm_dyn_segs =
}
PR_MEM("%s: %s: updated dynamic seg list:\n",
PR_MEM("%s: adding back remaining portion"
" of %s, memlist:\n",
}
#ifdef DEBUG
/*
* Renaming s_mp->sbm_del_mlist is not necessary. This
* list is not used beyond this point, and in fact, is
* disposed of at the end of this function.
*/
}
PR_MEM("%s: renamed source delete memlist", f);
#endif
}
/* delete target's entire address space */
if (err)
/*
* for the source board (which is now located on the
* target board) may now have some excess to be deleted.
* The amount is calculated by masking the slice
* info and keeping the slice offset from t_new_basepa.
*/
if (err)
} else {
/* delete board's entire address space */
if (err)
}
/* clean up target mem unit */
/* no need to delete sbm_mlist, it shares sbm_del_mlist */
/* reduce target size if new PAs go past end of usable slice */
if (t_new_smallsize > 0) {
PR_MEM("%s: target new size 0x%lx bytes\n",
f, t_new_smallsize);
}
}
/*
* work that was done in dr_release_mem_done.
*/
}
/*
* clean up (source) board's mem unit structure.
* NOTE: sbm_mlist is retained if no error has been record (in other
* words, when s_mp->sbm_cm.sbdev_error is NULL). This memlist is
* referred to elsewhere as the cached memlist. The cached memlist
* is used to re-attach (configure back in) this memunit from the
* unconfigured state. The memlist is retained because it may
* represent bad pages that were detected while the memory was
* configured into the OS. The OS deletes bad pages from phys_install.
* Those deletes, if any, will be represented in the cached mlist.
*/
}
}
return (0);
}
/*
* 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.
*/
int
{
int d;
int err_flag = 0;
static fn_t f = "dr_pre_release_mem";
PR_MEM("%s...\n", f);
for (d = 0; d < devnum; d++) {
int rv;
err_flag = 1;
continue;
} else if (!kcage_on) {
err_flag = 1;
continue;
}
/*
* Board is currently involved in a delete
* memory operation. Can't detach this guy until
* that operation completes.
*/
err_flag = 1;
break;
}
/*
* Check whether the detaching memory requires a
* copy-rename.
*/
&mq);
err_flag = 1;
break;
}
if (mq.nonrelocatable != 0) {
if (!(dr_cmd_flags(hp) &
(SBD_FLAG_FORCE | SBD_FLAG_QUIESCE_OKAY))) {
/* caller wasn't prompted for a suspend */
err_flag = 1;
break;
}
}
/* flags should be clean at this time */
}
err_flag = 1;
PR_MEM("%s: no memlist found for %s\n",
continue;
}
/* allocate a kphysm handle */
err_flag = 1;
break;
}
if ((mq.nonrelocatable != 0) ||
/*
* Either the detaching memory node contains
* non-reloc memory or we failed to reserve the
* detaching memory node (which did _not_ have
* any non-reloc memory, i.e. some non-reloc mem
* got onboard).
*/
int rv;
/*
* We had no luck locating a target
* memory node to be the recipient of
* the non-reloc memory on the node
* we're trying to detach.
* Clean up be disposing the mem handle
* and the mem list.
*/
/*
* can do nothing but complain
* and hope helpful for debug
*/
" kphysm_del_release return"
" value %d",
f, rv);
}
/* make sure sbm_flags is clean */
err_flag = 1;
break;
}
/*
* ml is not memlist_delete'd here because
* it has been assigned to mp->sbm_mlist
* by dr_select_mem_target.
*/
} else {
/* no target needed to detach this board */
}
#ifdef DEBUG
" selected target board %s\n",
f,
} else {
}
#endif
}
return (err_flag ? -1 : 0);
}
void
{
int rv;
static fn_t f = "dr_release_mem_done";
/*
* This unit will be flagged with DR_MFLAG_SOURCE, if it
* has a target unit.
*/
} else {
/* this is no target unit */
}
/* free delete handle */
/*
* can do nothing but complain
* and hope helpful for debug
*/
" return value %d", f, rv);
}
/*
* If an error was encountered during release, clean up
* the source (and target, if present) unit data.
*/
/* XXX Can we know that sbdev_error was encountered during release? */
PR_MEM("%s: %s: error %d noted\n",
f,
}
}
}
/* bail out */
return;
}
/*
* the kphysm delete operation that drained the source
* board also drained this target board. Since the source
* board drain is now known to have succeeded, we know this
* target board is drained too.
*
* because DR_DEV_SET_RELEASED and dr_device_transition
* is done here, the dr_release_dev_done should not
* fail.
*/
/*
* NOTE: do not transition target's board state,
* even if the mem-unit was the last configure
* this mem-unit will transitioned back to
* the configured state. In the meantime, the
* board's must remain as is.
*/
}
/* if board(s) had deleted memory, verify it is gone */
rv = 0;
}
}
if (rv) {
"deleted memory still found in phys_install",
f,
return;
}
/* this should not fail */
/* catch this in debug kernels */
ASSERT(0);
return;
}
PR_MEM("%s: marking %s release DONE\n",
/* should not fail */
if (rv != 0) {
/* catch this in debug kernels */
ASSERT(0);
return;
}
PR_MEM("%s: marking %s release DONE\n",
}
}
/*ARGSUSED*/
int
{
static fn_t f = "dr_disconnect_mem";
#ifdef DEBUG
#endif
PR_MEM("%s...\n", f);
}
/*
* Remove memory from lgroup
* For now, only board info is required.
*/
return (0);
}
int
{
static fn_t f = "dr_cancel_mem";
/* must cancel source board, not target board */
/* TODO: set error */
return (-1);
/* must always match the source board's state */
/* TODO: is this assertion correct? */
} else {
/* this is no target unit */
}
switch (state) {
case DR_STATE_UNREFERENCED: /* state set by dr_release_dev_done */
PR_MEM("%s: undoing target %s memory delete\n",
}
PR_MEM("%s: undoing %s memory delete\n",
}
/*FALLTHROUGH*/
/* TODO: should no longer be possible to see the release state here */
case DR_STATE_RELEASE: /* state set by dr_release_mem_done */
}
}
}
return (0);
default:
PR_MEM("%s: WARNING unexpected state (%d) for %s\n",
return (-1);
}
/*NOTREACHED*/
}
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 */
/* get basepfn of mem unit */
if (err) {
} else
/* attempt to get number of pages from PDA */
if (err) {
mp->sbm_npages = 0;
} else
/* if didn't work, calculate using memlist */
if (mp->sbm_npages == 0) {
/*
* Either we couldn't open the PDA or our
* PDA has garbage in it. We must have the
* page count consistent and whatever the
* OS states has precedence over the PDA
* so let's check the kernel.
*/
/* TODO: curious comment. it suggests pda query should happen if this fails */
PR_MEM("%s: PDA query failed for npages."
" Checking memlist for %s\n",
}
if (err) {
mp->sbm_alignment_mask = 0;
} else
if (err) {
} else
/*
* Add memory to lgroup
*/
PR_MEM("%s: %s (basepfn = 0x%lx, npgs = %ld)\n",
}
static int
{
int err;
static fn_t f = "dr_reserve_mem_spans";
PR_MEM("%s...\n", f);
/*
* Walk the supplied memlist scheduling each span for removal
* with kphysm_del_span. It is possible that a span may intersect
* an area occupied by the cage.
*/
" unexpected kphysm_del_span return value %d;"
" basepfn=0x%lx npages=%ld",
return (-1);
}
}
return (0);
}
/* debug counters */
int dr_smt_realigned;
#ifdef DEBUG
#endif
/*
* given source board.
* All boards in the system are examined and categorized in relation to
* their memory size versus the source board's memory size. Order of
* preference is:
* 1st: board has same memory size
* 2nd: board has larger memory size
* 3rd: board has smaller memory size
* 4th: board has smaller memory size, available memory will be reduced.
* Boards in category 3 and 4 will have their MC's reprogrammed to locate the
* span to which the MC responds to address span that appropriately covers
* the nonrelocatable span of the source board.
*/
static int
{
int n_units_per_set;
int idx;
int t_bd;
int t_unit;
int rv;
static fn_t f = "dr_select_mem_target";
PR_MEM("%s...\n", f);
/* calculate the offset into the slice of the last source board pfn */
/*
* Make one pass through all memory units on all boards
* and categorize them with respect to the source board.
*/
/*
* The board structs are a contiguous array
* so we take advantage of that to find the
* correct board struct pointer for a given
* board number.
*/
/* source board can not be its own target */
continue;
/* this memory node must be attached */
continue;
/* source unit can not be its own target */
/* catch this is debug kernels */
ASSERT(0);
continue;
}
/*
* this memory node must not already be reserved
* by some other memory delete operation.
*/
continue;
/*
* categorize the memory node
* If this is a smaller memory node, create a
* temporary, edited copy of the source board's
* memlist containing only the span of the non-
* relocatable pages.
*/
preference = 0;
t_mp->sbm_slice_offset = 0;
/*
* Selecting this target will require modifying
* ranges. Skip if not supported by platform.
*/
if (!allow_src_memrange_modify ||
PR_MEM("%s: skip target %s, memory "
"range relocation not supported "
"by platform\n", f,
continue;
}
preference = 1;
t_mp->sbm_slice_offset = 0;
} else {
/*
* Selecting this target will require modifying
* ranges. Skip if not supported by platform.
*/
if (!allow_src_memrange_modify ||
PR_MEM("%s: skip target %s, memory "
"range relocation not supported "
"by platform\n", f,
continue;
}
/*
* Check if its mc can be programmed to relocate
* the active address range to match the
* nonrelocatable span of the source board.
*/
preference = 2;
if (s_mq.phys_pages == 0) {
/*
* find non-relocatable span on
* source board.
*/
PR_MEM("%s: %s: unexpected"
" kphysm_del_span_query"
" return value %d;"
" basepfn 0x%lx,"
" npages %ld\n",
f,
rv,
s_mp->sbm_npages);
/* paranoia */
s_mq.phys_pages = 0;
continue;
}
/* more paranoia */
/*
* this should not happen
* if it does, it simply means that
* we can not proceed with qualifying
* this target candidate.
*/
if (s_mq.nonrelocatable == 0)
continue;
PR_MEM("%s: %s: nonrelocatable"
" span (0x%lx..0x%lx)\n",
f,
}
/*
* Round down the starting pfn of the
* nonrelocatable span on the source board
* to nearest programmable boundary possible
* with this target candidate.
*/
/* skip candidate if memory is too small */
continue;
/*
* reprogramming an mc to relocate its
* active address range means the beginning
* address to which the DIMMS respond will
* be somewhere above the slice boundary
* address. The larger the size of memory
* on this unit, the more likely part of it
* will exist beyond the end of the slice.
* The portion of the memory that does is
* unavailable to the system until the mc
* reprogrammed to a more favorable base
* address.
* An attempt is made to avoid the loss by
* recalculating the mc base address relative
* to the end of the slice. This may produce
* a more favorable result. If not, we lower
* the board's preference rating so that it
* is one the last candidate boards to be
* considered.
*/
pfn_t p;
/*
* calculate an alternative starting
* address relative to the end of the
* slice's address space.
*/
p = p & ~t_mp->sbm_alignment_mask;
if ((p > s_mq.first_nonrelocatable) ||
(p + t_mp->sbm_npages <
/*
* alternative starting addr
* won't work. Lower preference
* rating of this board, since
* some number of pages will
* unavailable for use.
*/
preference = 3;
} else {
pfn = p;
}
}
/*
* translate calculated pfn to an offset
* relative to the slice boundary. If the
* candidate board is selected, this offset
* will be used to calculate the values
* programmed into the mc.
*/
PR_MEM("%s: %s:"
" proposed mc offset 0x%lx\n",
f,
}
/* calculate index to start of preference set */
/* calculate offset to respective element */
}
}
/*
* NOTE: this would be a good place to sort each candidate
* set in to some desired order, e.g. memory size in ascending
* order. Without an additional sorting step here, the order
* within a set is ascending board number order.
*/
/* cleanup t_ml after previous pass */
}
/* get candidate target board mem unit */
continue;
/* get target board memlist */
" mem-unit %d, board %d",
f,
continue;
}
/* get appropriate source board memlist */
/*
* make a copy of the source board memlist
* then edit it to remove the spans that
* are outside the calculated span of
* [pfn..s_mq.last_nonrelocatable].
*/
PR_MEM("%s: memlist_dup failed\n", f);
/* TODO: should abort */
continue;
}
/* trim off lower portion */
if (excess > 0) {
x_ml,
}
/*
* Since this candidate target board is smaller
* than the source board, s_mq must have been
* initialized in previous loop while processing
* this or some other candidate board.
* FIXME: this is weak.
*/
/* trim off upper portion */
if (excess > 0) {
pfn_t p;
x_ml,
_ptob64(p),
}
PR_MEM("%s: %s: edited source memlist:\n",
#ifdef DEBUG
/* sanity check memlist */
#endif
/*
* x_ml now describes only the portion of the
* source board that will be moved during the
*/
} else {
/* use original memlist; all spans will be moved */
}
/* verify target can support source memory spans. */
PR_MEM("%s: source memlist won't"
" fit in target memlist\n", f);
PR_MEM("%s: source memlist:\n", f);
PR_MEM("%s: target memlist:\n", f);
continue;
}
/* NOTE: the value of d_ml is not used beyond this point */
PR_MEM("%s: checking for no-reloc in %s, "
" basepfn=0x%lx, npages=%ld\n",
f,
t_mp->sbm_npages);
PR_MEM("%s: kphysm_del_span_query:"
" unexpected return value %d\n", f, rv);
continue;
}
if (mq.nonrelocatable != 0) {
PR_MEM("%s: candidate %s has"
" nonrelocatable span [0x%lx..0x%lx]\n",
f,
continue;
}
#ifdef DEBUG
/*
* This is a debug tool for excluding certain boards
* from being selected as a target board candidate.
* dr_ignore_board is only tested by this driver.
* favorite debugger.
*/
if (dr_ignore_board &
PR_MEM("%s: dr_ignore_board flag set,"
" ignoring %s as candidate\n",
continue;
}
#endif
/*
* Reserve excess source board memory, if any.
*
* When the number of pages on the candidate target
* board is less than the number of pages on the source,
* then some spans (clearly) of the source board's address
* space will not be covered by physical memory after the
* schedules those spans to be deleted.
*/
PR_MEM("%s: cant dup src brd memlist\n", f);
/* TODO: should abort */
continue;
}
/* calculate base pfn relative to target board */
/*
* cannot split dynamically added segment
*/
PR_MEM("%s: proposed src delete pa=0x%lx\n", f,
s_del_pa);
PR_MEM("%s: checking for split of dyn seg list:\n", f);
break;
}
}
/* remove span that will reside on candidate board */
PR_MEM("%s: %s: reserving src brd memlist:\n",
/* reserve excess spans */
!= 0) {
/* likely more non-reloc pages appeared */
/* TODO: restart from top? */
continue;
}
} else {
/* no excess source board memory */
}
/*
* reserve all memory on target board.
* NOTE: source board's memhandle is used.
*
* If this succeeds (eq 0), then target selection is
* complete and all unwanted memory spans, both source and
* target, have been reserved. Loop is terminated.
*/
PR_MEM("%s: %s: target board memory reserved\n",
/* a candidate target board is now reserved */
/* *** EXITING LOOP *** */
break;
}
/* did not successfully reserve the target board. */
PR_MEM("%s: could not reserve target %s\n",
/*
* NOTE: an undo of the dr_reserve_mem_span work
* will happen automatically when the memhandle
* (s_mp->sbm_memhandle) is kphysm_del_release'd.
*/
}
/* clean up after memlist editing logic */
/*
* c_mp will be NULL when the entire sets[] array
* has been searched without reserving a target board.
*/
PR_MEM("%s: %s: target selection failed.\n",
return (-1);
}
PR_MEM("%s: found target %s for source %s\n",
f,
PR_MEM("%s: upsize detected (source=%ld < target=%ld)\n",
PR_MEM("%s: downsize detected (source=%ld > target=%ld)\n",
}
return (0);
}
/*
* Memlist support.
*/
/*
* Determine whether the source memlist (s_mlist) will
* fit into the target memlist (t_mlist) in terms of
* size and holes (i.e. based on same relative base address).
*/
static int
{
int rv = 0;
return (0);
/*
* Base both memlists on common base address (0).
*/
break;
}
}
/*
* If we ran out of source memlist chunks that mean
* we found a home for all of them.
*/
rv = 1;
/*
* Need to add base addresses back since memlists
* are probably in use by caller.
*/
return (rv);
}