/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished proprietary information of BroadOn Communications Corp.,
 *  and are protected by federal copyright law. They may not be disclosed
 *  to third parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 *  Description:
 *      This file implements standard IO functions using semi-hosting
 *
 */
#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>

#include <ahb_fdl_defs.h>
#include <sys.h>

/* XXX horti: Accessing AHM registers needs all manner of workarounds for
 * hardware bugs. This hopefully works, since we are running out of SRAM
 * and when this code is run the interrupts haven't been enabled yet & the
 * PPC is in reset.
 */
/* ppcRegionSize is specified in MB */
IOSError
setupDDRCGboundary(u32 ppcRegionSize)
{
    u32 reg = 0;
    reg |= AHMSECDDR_REG_COARSE_EN_DDR_MASK;/* Enable coarse-grained check */
    reg |= (ppcRegionSize) << AHMSECDDR_REG_BASE_ADDR_DDR_COARSE_SHIFT; /* total size MB */
    /* Allow any mem writes to complete */
    busDelay(1000);
    busWrt32(AHMSECDDR_TRUSTED, reg);
    busDelay(1000);
    if ( reg != busRd32(AHMSECDDR_TRUSTED)) 
        return IOS_ERROR_INVALID;
    else
        return IOS_ERROR_OK;
}
