Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: serial_4v.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef __SERIAL_4V__ | |
24 | #define __SERIAL_4V__ | |
25 | ||
26 | #include <pthread.h> | |
27 | #include "module.h" | |
28 | #include "arg.h" | |
29 | #include "console.h" | |
30 | #include "types.h" | |
31 | ||
32 | /* | |
33 | * Registers (8-bits only - 8byte addressing, upper bits read 0 write ignored) | |
34 | * num RW Function: | |
35 | * 0 R Input data register | |
36 | * 0 W Output data register | |
37 | * 1 RW Interrupt enable register | |
38 | * 2 R Interrupt indentification register | |
39 | * 2 W FIFO control register | |
40 | * 3 RW Line control register | |
41 | * 4 RW Modem control register | |
42 | * 5 RW Line status register | |
43 | * 6 RW Modem status register | |
44 | * 7 RW Scratch register | |
45 | * 8 RW Divisor lo | |
46 | * 9 RW Divisor hi | |
47 | * | |
48 | * See 16550 data sheet p 14 - table M | |
49 | */ | |
50 | ||
51 | ||
52 | extern "C"{ | |
53 | int serial_4v_ui_cmd(void*, int argc, char * argv[]); | |
54 | } | |
55 | ||
56 | class serial4v:public Module{ | |
57 | ||
58 | uint64_t start_pa; | |
59 | uint64_t end_pa; | |
60 | uint64_t size; | |
61 | bool log; | |
62 | char * logfile; | |
63 | console * Console; | |
64 | int portCon; | |
65 | char * portConName; | |
66 | bool pop; | |
67 | uint8_t line_status; | |
68 | uint8_t scratch; | |
69 | bool kill_xterm_on_exit; | |
70 | const char * fg; | |
71 | const char * bg; | |
72 | const char * font; | |
73 | const char * exec; | |
74 | const char * title; | |
75 | bool raw; // if the logging is enabled, whether it is buffered or not | |
76 | bool append; // if false, truncate the log file if it exists | |
77 | ||
78 | pthread_mutex_t mutty; | |
79 | ||
80 | static const int MaxBuf = 256 * 1024; | |
81 | struct { | |
82 | uint8_t bufp[MaxBuf]; | |
83 | int head; | |
84 | int tail; | |
85 | int count; | |
86 | int size; | |
87 | } in; | |
88 | ||
89 | static const int DS_LSTAT_DATA_READY = 0x1; | |
90 | static const int DS_LSTAT_OVERRUN = 0x2; | |
91 | static const int DS_LSTAT_PARTIY_ERR = 0x4; | |
92 | static const int DS_LSTAT_FRAMING_ERR = 0x8; | |
93 | static const int DS_LSTAT_BREAK = 0x10; | |
94 | static const int DS_LSTAT_TX_HOLD = 0x20; | |
95 | static const int DS_LSTAT_TX_EMPTY = 0x40; | |
96 | static const int DS_LSTAT_RCV_ERR = 0x80; | |
97 | ||
98 | public: | |
99 | typedef enum { | |
100 | DS_Input = 0x0, /* RO */ | |
101 | DS_Output = 0x0, /* WO */ | |
102 | DS_IntEnable = 0x1, | |
103 | DS_IntIdent = 0x2, /* RO */ | |
104 | DS_FIFOCtrl = 0x2, /* WO */ | |
105 | DS_LineCtrl = 0x3, | |
106 | DS_ModemCtrl = 0x4, | |
107 | DS_LineStatus = 0x5, | |
108 | DS_ModemStatus = 0x6, | |
109 | DS_Scratch = 0x7, | |
110 | DS_DivLo = 0x8, | |
111 | DS_DivHi = 0x9 | |
112 | } ds_reg_t; | |
113 | ||
114 | const char *get_help(); | |
115 | bool parse_arg(const char *); | |
116 | bool check_args(); | |
117 | void init_done(); | |
118 | void module_added(mmi_instance_t, const char*){return; } | |
119 | void module_deleted(mmi_instance_t, const char*){return;} | |
120 | void modinfo(){ | |
121 | fprintf(stderr,"%s: sun4v serial module\n",getName()); | |
122 | fprintf(stderr," logfile <%s> %s\n",logfile? logfile:"none",(log && raw)?"raw mode":""); | |
123 | fprintf(stderr," for console tip %s\n",portConName); | |
124 | if(fg) fprintf(stderr," xterm fg set to %s\n",fg); | |
125 | if(bg) fprintf(stderr," xterm bg set to %s\n",bg); | |
126 | if(font) fprintf(stderr," xterm font set to %s\n",font); | |
127 | if(exec) fprintf(stderr," e set to %s\n",exec); | |
128 | } | |
129 | void *get_interface(const char*){return 0;} | |
130 | ||
131 | static void getConsoleIp(void *data,unsigned char *ip, int port); | |
132 | static int serial4v_physio_access(uint32_t cpuid, void* obj, uint64_t paddr, | |
133 | mmi_bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask); | |
134 | void serial4v_ld (uint64_t paddr, uint64_t *buf, int size); | |
135 | void serial4v_st(uint64_t paddr, uint64_t *buf, int size); | |
136 | serial4v(const char *, const char *); | |
137 | ~serial4v(){ | |
138 | if(kill_xterm_on_exit){ | |
139 | fprintf(stderr,"%s : closing xterm window\n", getName()); | |
140 | Console->kill_term(portCon); | |
141 | } | |
142 | } | |
143 | ||
144 | bool dump(FILE *fp){ Console->dump(portCon,fp); return true; } | |
145 | bool restore(FILE *fp) { Console->restore(portCon,fp); return true; } | |
146 | ||
147 | void handle_ui(int argc, char * argv[]); | |
148 | void ui_cmd_usage(){ | |
149 | fprintf(stderr,"ui format: %s <command> <command args> ... \n",getName()); | |
150 | fprintf(stderr,"%s supports following UI commands\n",getName()); | |
151 | fprintf(stderr," send <some char string>\n\ | |
152 | echo the character string appended with a new line to the console.\n"); | |
153 | fprintf(stderr," sendfile <filename>\n\ | |
154 | echo the contents of \'filename\' to console\n"); | |
155 | fprintf(stderr," Note1: the commands above simulate i/p from console\n\ | |
156 | hence, the o/p echoed on xterm depends upon Solaris/OBP serial driver\n"); | |
157 | fprintf(stderr," debug [<level>]\n\ | |
158 | set the debug level for debug prints to 'level'\n\ | |
159 | if 'level' not provided, print current debug level\n\ | |
160 | 'level' = [0|1|2]\n"); | |
161 | fprintf(stderr," pop \n\ | |
162 | pop up the xterm console if not already opened\n"); | |
163 | fprintf(stderr," kill\n\ | |
164 | kill the xterm console if opened\n"); | |
165 | fprintf(stderr," fg [<color>]\n\ | |
166 | set the foreground color of xterm to `color`, else report current\n"); | |
167 | fprintf(stderr," bg [<color>]\n\ | |
168 | set the foreground color of xterm to `color`, else report current\n"); | |
169 | fprintf(stderr," font [<font>]\n\ | |
170 | set the font of xterm to `font`, else report current\n"); | |
171 | fprintf(stderr," Note2: user should make sure that fg,bg etc are valid\n\ | |
172 | inputs to xterm program. xterm should be `kill`ed and `pop`ed\n\ | |
173 | for new fg, bg, font values to take effect\n"); | |
174 | fprintf(stderr," Note3: default fg=black, bg=gray90\n\ | |
175 | font=-dec-terminal-medium-r-normal-*-14-140-*-75-c-80-iso8859-1\n"); | |
176 | } | |
177 | ||
178 | }; | |
179 | ||
180 | #endif //__SERIAL_4V__ |