// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: tod.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 ============================================
* Fake time of the day device.
* Returns time from the host machine.
* Copyright (c) 2006 by Sun Microsystems, Inc.
#include <sys/syscall.h> // get exec number
#include <sys/types.h> // uid_t
#include <unistd.h> // getuid()
extern "C" int tod_access(uint32_t cpuid
, void* obj
, uint64_t paddr
, mmi_bool_t wr
, uint32_t size
, uint64_t* buf
, uint8_t bytemask
);
int tod_ld_operation (void *cd
, uint64_t paddr
, uint64_t *buf
, int sz
, uint32_t cpuid
);
int tod_st_operation (void *cd
, uint64_t paddr
, uint64_t *buf
, int sz
, uint32_t cpuid
);
extern "C" void tod_create_instance (const char *modname
, const char *instance_name
);
if (! mmi_register_instance_creator("tod", tod_create_instance
) ) {
ui
->error("Cannot register instance creator for tod\n");
void tod_create_instance (const char *modname
, const char *instance_name
)
sam_tod_s
* tod_obj
= new sam_tod_s
;
mmi_instance_t instance
= mmi_register_instance(modname
, instance_name
, (void *) &tod_obj
, "tod dummy device");
// expected syntax: sysconf tod tod1 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
);
tod_obj
->startpa
= strtoull(rv
, NULL
, 0);
perror("tod: error parsing startpa");
} else if (strcmp(lv
, "endpa") == 0) {
char * rv
= strtok_r(NULL
, "=", &marker
);
tod_obj
->endpa
= strtoull(rv
, NULL
, 0);
perror("tod: error parsing endpa");
tod_obj
->sz
= tod_obj
->endpa
- tod_obj
->startpa
+ 1;
if (mmi_map_physio(tod_obj
->startpa
, tod_obj
->sz
, (void *) tod_obj
, tod_access
)) {
ui
->error(" sam tod: unable to register IO interceptor\n");
int tod_access(uint32_t cpuid
, void* obj
, uint64_t paddr
, mmi_bool_t wr
, uint32_t size
, uint64_t* buf
, uint8_t bytemask
)
return tod_st_operation(obj
, paddr
, buf
, size
, cpuid
);
return tod_ld_operation(obj
, paddr
, buf
, size
, cpuid
);
int tod_ld_operation (void *obj
, uint64_t paddr
, uint64_t *buf
, int size
, uint32_t cpuid
)
sam_tod_s
* tod_obj
= (sam_tod_s
*) obj
;
uint64_t offset
= paddr
- tod_obj
->startpa
;
if ((offset
== 0) && (size
== 8))
fprintf(stderr
, "SAM tod: ld_operation pa 0x%llx size %d cpu %d\n", paddr
, size
, cpuid
);
} // int tod_ld_operation ()
int tod_st_operation (void *obj
, uint64_t paddr
, uint64_t *buf
, int size
, uint32_t cpuid
)
fprintf(stderr
, "SAM tod: st_operation pa 0x%llx size %d cpu %d, ignored\n", paddr
, size
, cpuid
);
} // int tod_st_operation ()
/////////////////////////////////////////////////
/////////////////////////////////////////////////