/*
* 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;
extern vnode_t *retired_pages;
/* TODO: push this reference below drmach line */
extern int kcage_on;
typedef enum {
memquery_t *mp);
/*
* 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;
}
dr_mem_del_done, (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 struct memlist *
{
static fn_t f = "dr_memlist_del_retired_pages";
PR_MEM("%s\n", f);
return (mlist);
}
do {
continue;
/*
* Page retirement currently breaks large pages into PAGESIZE
* pages. If this changes, need to remove the assert and deal
* with different page sizes.
*/
PR_MEM("deleted retired page 0x%lx (pfn 0x%lx) "
}
return (mlist);
}
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.
*/
}
/*
* Remove retired pages from the copy list. The page content
* need not be copied since the pages are no longer in use.
*/
PR_MEM("%s: copy list before removing retired pages (if any):\n", f);
PR_MEM("%s: copy list after removing retired pages:\n", f);
/*
* With parallel copy, it shouldn't make a difference which
* CPU is the actual master during copy-rename since all
* CPUs participate in the parallel copy anyway.
*/
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 */
goto done;
}
/* Resume the OS. */
goto done;
/*
* Rename memory for lgroup.
* Source and target board numbers are packaged in arg.
*/
PR_MEM("%s: copy-rename elapsed time = %ld ticks (%ld secs)\n",
rv = 0;
done:
if (srhp)
if (err)
return (rv);
}
/*
* 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;
}
}
/*
* 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);
}
}
/*
* 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->last_nonrelocatable = 0;
if (rv)
break;
if (mq.nonrelocatable != 0) {
}
}
if (mp->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.
*/
}
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);
}
static void
{
void (*mc_update_mlist)(void);
/*
* mc-opl is configured during drmach_mem_new but the memory
* has not been added to phys_install at that time.
* we must inform mc-opl to update the mlist after we
* attach or detach a system board.
*/
mc_update_mlist = (void (*)(void))
modgetsymvalue("opl_mc_update_mlist", 0);
if (mc_update_mlist != NULL) {
(*mc_update_mlist)();
}
}
int
{
int d;
static fn_t f = "dr_post_attach_mem";
PR_MEM("%s...\n", f);
for (d = 0; d < devnum; d++) {
/* OPL supports memoryless board */
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.
*/
}
}
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
{
return (1);
}
return (0);
}
static sbd_error_t *
{
static fn_t f = "dr_process_excess_mlist";
int rv;
/*
* After the small <-> big copy-rename,
* the original address space for the
* source board may have excess to be
* deleted. This is a case different
* from the big->small excess source
* memory case listed below.
* Remove s_mp->sbm_del_mlist from
* the kernel cage glist.
*/
PR_MEM("%s: delete small<->big copy-"
"rename source excess memory", f);
if (err)
DRERR_SET_C(&s_mp->
}
PR_MEM("%s: adding back remaining portion"
" of %s, memlist:\n",
/*
* If the memory object is 256 MB aligned (max page size
* on OPL, it will not be coalesced to the adjacent memory
* chunks. The coalesce logic assumes contiguous page
* structures for contiguous memory and we hit panic.
* For anything less than 256 MB alignment, we have
* to make sure that it is not adjacent to anything.
* If the new chunk is adjacent to phys_install, we
* truncate it to 4MB boundary. 4 MB is somewhat
* arbitrary. However we do not want to create
* very small segments because they can cause problem.
* The extreme case of 8K segment will fail
* kphysm_add_memory_dynamic(), e.g.
*/
if (rv) {
t_mp->sbm_dyn_segs =
continue;
}
t_mp->sbm_dyn_segs =
}
continue;
}
if (rv) {
t_mp->sbm_dyn_segs =
continue;
}
t_mp->sbm_dyn_segs =
}
}
}
}
return (err);
}
static int
{
/* old and new below refer to PAs before and after copy-rename */
int rv;
int s_excess_mem_deleted = 0;
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;
/*
* 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);
PR_MEM("%s: source dyn seg 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)
/*
* Add back excess target memory.
* Subtract out the portion of the target memory
* node that was taken over by the source memory
* node.
*/
}
PR_MEM("%s: excess memlist:\n", f);
/*
* Update dynamically added segs
*/
t_mp->sbm_dyn_segs =
}
t_mp->sbm_dyn_segs =
}
PR_MEM("%s: %s: updated dynamic seg list:\n",
if (t_excess_mlist != NULL) {
s_excess_mem_deleted = 1;
}
#ifdef DEBUG
/*
* s_mp->sbm_del_mlist may still needed
*/
PR_MEM("%s: source delete memeory flag %d",
f, s_excess_mem_deleted);
PR_MEM("%s: 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.
* Those excess memory on the source board are kept in
* source board's sbm_del_mlist
*/
PR_MEM("%s: delete source excess memory", f);
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 */
}
/*
* 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;
}
/* flags should be clean at this time */
}
err_flag = 1;
PR_MEM("%s: no memlist found for %s\n",
continue;
}
/*
* Check whether the detaching memory requires a
* copy-rename.
*/
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;
}
}
/* 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? */
}
}
}
/* 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 */
return;
}
/*
* 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:
* 2nd copy all source, larger target
* 3rd copy nonrelocatable source span
*/
static int
{
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 */
/*
* 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",
s_mp->sbm_npages);
return (-1);
}
PR_MEM("%s: %s: nonrelocatable span (0x%lx..0x%lx)\n", f,
/* break down s_ml if it contains dynamic segments */
}
/*
* 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;
/* get target board memlist */
" mem-unit %d, board %d", f,
continue;
}
if (preference == DR_TP_INVALID)
continue;
/* 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;
}
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.
*
* Only the nonrelocatable source span will be copied
* so schedule the rest of the source mem to be deleted.
*/
switch (preference) {
case DR_TP_NONRELOC:
/*
* Get source copy memlist and use it to construct
* delete memlist.
*/
/* XXX */
}
PR_MEM("%s: %s: reserving src brd memlist:\n", f,
/* reserve excess spans */
d_ml) != 0) {
/* likely more non-reloc pages appeared */
/* TODO: restart from top? */
continue;
}
break;
default:
break;
}
/*
* 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,
return (0);
}
/*
* Returns target preference rank:
* -1 not a valid copy-rename target board
* 1 copy all source, larger target
* 2 copy nonrelocatable source span
*/
static dr_target_pref_t
{
static fn_t f = "dr_get_target_preference";
/*
* Can the entire source board be copied?
*/
else
} else {
/*
* Entire source won't fit so try non-relocatable memory only
* (target aligned).
*/
if (s_nonreloc_ml == NULL) {
PR_MEM("%s: dr_get_nonreloc_mlist failed\n", f);
}
else
}
if (s_nonreloc_ml != NULL)
/*
* Force floating board preference lower than all other boards
* if the force flag is present; otherwise disallow the board.
*/
else
}
return (preference);
}
/*
* Create a memlist representing the source memory that will be copied to
* the target board. The memory to be copied is the maximum amount that
* will fit on the target board.
*/
static struct memlist *
{
static fn_t f = "dr_get_copy_mlist";
/* XXX */
/*
* To construct the source copy memlist:
*
* The target memlist is converted to the post-rename
* source addresses. This is the physical address range
* the target will have after the copy-rename. Overlaying
* and deleting this from the current source memlist will
* give the source delete memlist. The copy memlist is
* the reciprocal of the source delete memlist.
*/
/*
* Normalize relative to target slice base PA
* in order to preseve slice offsets.
*/
/*
* Convert to source slice PA address.
*/
}
}
/*
* Expand the delete mlist to fully include any dynamic segments
* it intersects with.
*/
}
}
}
PR_MEM("%s: source delete mlist\n", f);
PR_MEM("%s: source copy mlist\n", f);
return (s_copy_ml);
}
/*
* Scan the non-relocatable spans on the source memory
* and construct a minimum mlist that includes all non-reloc
* memory subject to target alignment, and dynamic segment
* constraints where only whole dynamic segments may be deleted.
*/
static struct memlist *
{
static fn_t f = "dr_get_nonreloc_mlist";
PR_MEM("%s: checking for split of dyn seg list:\n", f);
int rv;
if (rv) {
return (NULL);
}
if (mq.nonrelocatable == 0)
continue;
PR_MEM("%s: non-reloc span: 0x%lx, 0x%lx (%lx, %lx)\n", f,
/*
* Align the span at both ends to allow for possible
* cage expansion.
*/
PR_MEM("%s: adjusted non-reloc span: 0x%lx, 0x%lx\n",
/*
* Expand the non-reloc span to fully include any
* dynamic segments it intersects with.
*/
}
}
PR_MEM("%s: source didn't have any non-reloc pages!\n", f);
return (NULL);
}
return (x_ml);
}
/*
* Check if source memlist can fit in target memlist while maintaining
* relative offsets within board.
*/
static int
{
int canfit = 0;
static fn_t f = "dr_mlist_canfit";
goto done;
}
/*
* Normalize to slice relative offsets.
*/
done:
return (canfit);
}
/*
* Memlist support.
*/
/*
* Determine whether the source memlist (s_mlist) will
* fit into the target memlist (t_mlist) in terms of
* size and holes. Assumes the caller has normalized the
* memlist physical addresses for comparison.
*/
static int
{
int rv = 0;
return (0);
break;
}
}
/*
* If we ran out of source memlist chunks that mean
* we found a home for all of them.
*/
rv = 1;
return (rv);
}