// ========== 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 ============================================
* handle mcu (Memory Control Unit) N1 addresses for blaze/SAM
* Copyright (c) 2004 by Sun Microsystems, Inc.
#include <sys/syscall.h> // get exec number
#include <sys/types.h> // uid_t
#include <unistd.h> // getuid()
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
);
if (! mmi_register_instance_creator("mcu", mcu_create_instance
) ) {
fprintf(stderr
, "ERROR: SAM MCU: Cannot register mcu instance creator\n");
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");
// expected syntax: sysconf mcu mcu1 startpa=<0xblah> endpa=<0xblah>
int argc
= mmi_argc(instance
);
char * arg
= strdup(mmi_argv(instance
, i
));
char * lv
= strtok_r(arg
, "=", &marker
);
if (strcmp(lv
, "startpa") == 0) {
char * rv
= strtok_r(NULL
, "=", &marker
);
mcu_obj
->startpa
= strtoull(rv
, NULL
, 0);
perror("mcu: error parsing startpa");
} else if (strcmp(lv
, "endpa") == 0) {
char * rv
= strtok_r(NULL
, "=", &marker
);
mcu_obj
->endpa
= strtoull(rv
, NULL
, 0);
perror("mcu: error parsing startpa");
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");
int mcu_access(uint32_t cpuid
, void* obj
, uint64_t paddr
, mmi_bool_t wr
, uint32_t size
, uint64_t* buf
, uint8_t bytemask
)
return mcu_st_operation(obj
, paddr
, buf
, size
, cpuid
);
return mcu_ld_operation(obj
, paddr
, buf
, size
, cpuid
);
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
);
if (verbose
) fprintf(stderr
, "mcu: ld from unknown paddr 0x%llx\n", paddr
);
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
);
if (verbose
) fprintf(stderr
, "mcu: st to unknown paddr 0x%llx\n", paddr
);
} // int mcu_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t v9cpuid)
/////////////////////////////////////////////////
/////////////////////////////////////////////////