/* Adapted from ATI's sys.c */
#include <iostypes.h>
#include <ios.h>
#include <iop.h>
#include <ioslibc.h>

#include <ahb_fdl_defs.h>
#include <mem_reg.h>
#include "sys_int.h"
#include <sys.h>
#include <lomem.h>

/*
 * Enable or disable PPC access to the EXI registers
 */
extern void iosFlushDCache(void *ptr, u32 size);
void
setAHBIOPI(u32 enable)
{
    u32 reg, val;
    OSLoMem *m = (OSLoMem *) RVL_LOMEM_BASE;

    reg = busRd32(ACR_AIPPROT_TRUSTED);
    val = enable ? 1 : 0;

    if (enable) {
        m->syncAHBPI = (u32)LOMEM_AHBPI_ENABLED;
    }
    else { 
        m->syncAHBPI = (u32)LOMEM_AHBPI_DISABLED; 
    }
    iosFlushDCache(m, sizeof(m));
    AIPPROT_SET_ENAHBIOPI(reg, val);
    busWrt32(ACR_AIPPROT_TRUSTED, reg);
}
