Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / dummy_mods / mcu / mcu.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: mcu.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
//
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
//
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// ========== Copyright Header End ============================================
/* mcu.C
* handle mcu (Memory Control Unit) N1 addresses for blaze/SAM
*
* Copyright (c) 2004 by Sun Microsystems, Inc.
* All rights reserved.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/syscall.h> // get exec number
#include <sys/types.h> // uid_t
#include <unistd.h> // getuid()
#include <inttypes.h>
#include <stdarg.h>
#include <thread.h>
#include "mmi.h"
#include "ui.h"
struct sam_mcu_s {
uint64_t startpa;
uint64_t endpa;
}; // struct sam_mcu_s
int verbose = 0;
static int mcu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid);
static int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid);
extern "C" static void mcu_create_instance (const char *modname, const char *instance_name);
extern "C" int mcu_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask);
extern "C" void _init()
{
if (! mmi_register_instance_creator("mcu", mcu_create_instance) ) {
fprintf(stderr, "ERROR: SAM MCU: Cannot register mcu instance creator\n");
}
} // _init()
void mcu_create_instance (const char *modname, const char *instance_name)
{
struct sam_mcu_s * mcu_obj = new sam_mcu_s;
mmi_instance_t instance = mmi_register_instance(modname, instance_name, mcu_obj, "SAM MCU model");
mcu_obj->startpa = 0x0;
mcu_obj->endpa = 0x0;
// expected syntax: sysconf mcu mcu1 startpa=<0xblah> endpa=<0xblah>
int argc = mmi_argc(instance);
int i;
for (i=0; i<argc; i++) {
char * arg = strdup(mmi_argv(instance, i));
char * marker;
char * lv = strtok_r(arg, "=", &marker);
if (strcmp(lv, "startpa") == 0) {
errno = 0;
char * rv = strtok_r(NULL, "=", &marker);
mcu_obj->startpa = strtoull(rv, NULL, 0);
if (errno) {
perror("mcu: error parsing startpa");
exit(1);
}
} else if (strcmp(lv, "endpa") == 0) {
errno = 0;
char * rv = strtok_r(NULL, "=", &marker);
mcu_obj->endpa = strtoull(rv, NULL, 0);
if (errno) {
perror("mcu: error parsing startpa");
exit(1);
}
} // else - do nothing
}
uint64_t sz = (mcu_obj->endpa - mcu_obj->startpa + 1);
if (mmi_map_physio(mcu_obj->startpa, sz, (void *) mcu_obj, mcu_access)) {
fprintf(stderr, " sam mcu: unable to register IO interceptor\n");
return;
}
}
int mcu_access(uint32_t cpuid, void* obj, uint64_t paddr, mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask)
{
if (wr) {
return mcu_st_operation(obj, paddr, buf, size, cpuid);
} else {
return mcu_ld_operation(obj, paddr, buf, size, cpuid);
}
} // mcu_access()
int mcu_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
{
if (verbose) fprintf(stderr, "mcu: ld_operation pa 0x%llx size %d cpu %d\n", paddr, size, v9cpuid);
switch (paddr) {
case 0x0:
*buf = 0;
break;
default:
if (verbose) fprintf(stderr, "mcu: ld from unknown paddr 0x%llx\n", paddr);
*buf = 0;
}
return 0;
} //
int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
{
if (verbose) fprintf(stderr, "mcu: st_operation pa 0x%llx size %d cpu %d\n", paddr, size, v9cpuid);
switch (paddr) {
break;
default:
if (verbose) fprintf(stderr, "mcu: st to unknown paddr 0x%llx\n", paddr);
}
return 0;
} // int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
/////////////////////////////////////////////////
extern "C" void _fini ()
{
}
/////////////////////////////////////////////////