Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / devices / serial_4v / include / serial_4v.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: serial_4v.h
* 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 ============================================
*/
#ifndef __SERIAL_4V__
#define __SERIAL_4V__
#include <pthread.h>
#include "module.h"
#include "arg.h"
#include "console.h"
#include "types.h"
/*
* Registers (8-bits only - 8byte addressing, upper bits read 0 write ignored)
* num RW Function:
* 0 R Input data register
* 0 W Output data register
* 1 RW Interrupt enable register
* 2 R Interrupt indentification register
* 2 W FIFO control register
* 3 RW Line control register
* 4 RW Modem control register
* 5 RW Line status register
* 6 RW Modem status register
* 7 RW Scratch register
* 8 RW Divisor lo
* 9 RW Divisor hi
*
* See 16550 data sheet p 14 - table M
*/
extern "C"{
int serial_4v_ui_cmd(void*, int argc, char * argv[]);
}
class serial4v:public Module{
uint64_t start_pa;
uint64_t end_pa;
uint64_t size;
bool log;
char * logfile;
console * Console;
int portCon;
char * portConName;
bool pop;
uint8_t line_status;
uint8_t scratch;
bool kill_xterm_on_exit;
const char * fg;
const char * bg;
const char * font;
const char * exec;
const char * title;
bool raw; // if the logging is enabled, whether it is buffered or not
bool append; // if false, truncate the log file if it exists
pthread_mutex_t mutty;
static const int MaxBuf = 256 * 1024;
struct {
uint8_t bufp[MaxBuf];
int head;
int tail;
int count;
int size;
} in;
static const int DS_LSTAT_DATA_READY = 0x1;
static const int DS_LSTAT_OVERRUN = 0x2;
static const int DS_LSTAT_PARTIY_ERR = 0x4;
static const int DS_LSTAT_FRAMING_ERR = 0x8;
static const int DS_LSTAT_BREAK = 0x10;
static const int DS_LSTAT_TX_HOLD = 0x20;
static const int DS_LSTAT_TX_EMPTY = 0x40;
static const int DS_LSTAT_RCV_ERR = 0x80;
public:
typedef enum {
DS_Input = 0x0, /* RO */
DS_Output = 0x0, /* WO */
DS_IntEnable = 0x1,
DS_IntIdent = 0x2, /* RO */
DS_FIFOCtrl = 0x2, /* WO */
DS_LineCtrl = 0x3,
DS_ModemCtrl = 0x4,
DS_LineStatus = 0x5,
DS_ModemStatus = 0x6,
DS_Scratch = 0x7,
DS_DivLo = 0x8,
DS_DivHi = 0x9
} ds_reg_t;
const char *get_help();
bool parse_arg(const char *);
bool check_args();
void init_done();
void module_added(mmi_instance_t, const char*){return; }
void module_deleted(mmi_instance_t, const char*){return;}
void modinfo(){
fprintf(stderr,"%s: sun4v serial module\n",getName());
fprintf(stderr," logfile <%s> %s\n",logfile? logfile:"none",(log && raw)?"raw mode":"");
fprintf(stderr," for console tip %s\n",portConName);
if(fg) fprintf(stderr," xterm fg set to %s\n",fg);
if(bg) fprintf(stderr," xterm bg set to %s\n",bg);
if(font) fprintf(stderr," xterm font set to %s\n",font);
if(exec) fprintf(stderr," e set to %s\n",exec);
}
void *get_interface(const char*){return 0;}
static void getConsoleIp(void *data,unsigned char *ip, int port);
static int serial4v_physio_access(uint32_t cpuid, void* obj, uint64_t paddr,
mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask);
void serial4v_ld (uint64_t paddr, uint64_t *buf, int size);
void serial4v_st(uint64_t paddr, uint64_t *buf, int size);
serial4v(const char *, const char *);
~serial4v(){
if(kill_xterm_on_exit){
fprintf(stderr,"%s : closing xterm window\n", getName());
Console->kill_term(portCon);
}
}
bool dump(FILE *fp){ Console->dump(portCon,fp); return true; }
bool restore(FILE *fp) { Console->restore(portCon,fp); return true; }
void handle_ui(int argc, char * argv[]);
void ui_cmd_usage(){
fprintf(stderr,"ui format: %s <command> <command args> ... \n",getName());
fprintf(stderr,"%s supports following UI commands\n",getName());
fprintf(stderr," send <some char string>\n\
echo the character string appended with a new line to the console.\n");
fprintf(stderr," sendfile <filename>\n\
echo the contents of \'filename\' to console\n");
fprintf(stderr," Note1: the commands above simulate i/p from console\n\
hence, the o/p echoed on xterm depends upon Solaris/OBP serial driver\n");
fprintf(stderr," debug [<level>]\n\
set the debug level for debug prints to 'level'\n\
if 'level' not provided, print current debug level\n\
'level' = [0|1|2]\n");
fprintf(stderr," pop \n\
pop up the xterm console if not already opened\n");
fprintf(stderr," kill\n\
kill the xterm console if opened\n");
fprintf(stderr," fg [<color>]\n\
set the foreground color of xterm to `color`, else report current\n");
fprintf(stderr," bg [<color>]\n\
set the foreground color of xterm to `color`, else report current\n");
fprintf(stderr," font [<font>]\n\
set the font of xterm to `font`, else report current\n");
fprintf(stderr," Note2: user should make sure that fg,bg etc are valid\n\
inputs to xterm program. xterm should be `kill`ed and `pop`ed\n\
for new fg, bg, font values to take effect\n");
fprintf(stderr," Note3: default fg=black, bg=gray90\n\
font=-dec-terminal-medium-r-normal-*-14-140-*-75-c-80-iso8859-1\n");
}
};
#endif //__SERIAL_4V__