dev_kn02ba.cc Source File

Back to the index.

dev_kn02ba.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2018 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * COMMENT: DEC KN02BA "3min" TurboChannel interrupt controller
29  *
30  * Used in DECstation 5000/1xx "3MIN". See include/dec_kmin.h for more info.
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "cpu.h"
38 #include "device.h"
39 #include "devices.h"
40 #include "interrupt.h"
41 #include "machine.h"
42 #include "memory.h"
43 #include "misc.h"
44 
45 #include "thirdparty/dec_kmin.h"
46 
47 
48 struct kn02ba_data {
50 
51  uint32_t mer; /* Memory Error Register */
52  uint32_t msr; /* Memory Size Register */
53 
54  struct interrupt irq;
55 };
56 
57 
58 /*
59  * kn02ba_interrupt_assert(), kn02ba_interrupt_deassert():
60  *
61  * Called whenever a kn02ba interrupt is asserted/deasserted.
62  */
64 {
65  struct kn02ba_data *d = (struct kn02ba_data *) interrupt->extra;
66  struct dec_ioasic_data *r = (struct dec_ioasic_data *) d->dec_ioasic;
67  r->intr |= interrupt->line;
69 }
71 {
72  struct kn02ba_data *d = (struct kn02ba_data *) interrupt->extra;
73  struct dec_ioasic_data *r = (struct dec_ioasic_data *) d->dec_ioasic;
74  r->intr &= ~interrupt->line;
76 }
77 
78 
79 DEVICE_ACCESS(kn02ba_mer)
80 {
81  struct kn02ba_data *d = (struct kn02ba_data *) extra;
82  uint64_t idata = 0, odata = 0;
83 
84  if (writeflag == MEM_WRITE)
85  idata = memory_readmax64(cpu, data, len);
86 
87  switch (relative_addr) {
88  case 0:
89  if (writeflag == MEM_WRITE)
90  d->mer = idata;
91  else
92  odata = d->mer;
93 
94  debug("[ kn02ba_mer: %s MER, data=0x%08x (%s %s %s %s %s %s %s) ]\n",
95  writeflag == MEM_WRITE ? "write to" : "read from",
96  d->mer,
97  d->mer & KMIN_MER_PAGE_BRY ? "PAGE_BRY" : "--",
98  d->mer & KMIN_MER_TLEN ? "TLEN" : "--",
99  d->mer & KMIN_MER_PARDIS ? "PARDIS" : "--",
100  d->mer & KMIN_LASTB31 ? "LASTB31" : "--",
101  d->mer & KMIN_LASTB23 ? "LASTB23" : "--",
102  d->mer & KMIN_LASTB15 ? "LASTB15" : "--",
103  d->mer & KMIN_LASTB07 ? "LASTB07" : "--"
104  );
105 
106  break;
107 
108  default:
109  if (writeflag == MEM_READ) {
110  fatal("[ kn02ba_mer: read from offset 0x%08lx ]\n",
111  (long)relative_addr);
112  } else {
113  fatal("[ kn02ba_mer: write to offset 0x%08lx: 0x%08x ]\n",
114  (long)relative_addr, (int)idata);
115  }
116  exit(1);
117  }
118 
119  if (writeflag == MEM_READ)
120  memory_writemax64(cpu, data, len, odata);
121 
122  return 1;
123 }
124 
125 
126 DEVICE_ACCESS(kn02ba_msr)
127 {
128  struct kn02ba_data *d = (struct kn02ba_data *) extra;
129  uint64_t idata = 0, odata = 0;
130 
131  if (writeflag == MEM_WRITE)
132  idata = memory_readmax64(cpu, data, len);
133 
134  switch (relative_addr) {
135  case 0:
136  if (writeflag == MEM_WRITE)
137  d->msr = idata;
138  else
139  odata = d->msr;
140 
141  debug("[ kn02ba_msr: %s MSR, data=0x%08x (%s) ]\n",
142  writeflag == MEM_WRITE ? "write to" : "read from",
143  d->msr,
144  d->msr & KMIN_MSR_SIZE_16Mb ? "16Mb" : "--"
145  );
146 
147  break;
148 
149  default:
150  if (writeflag == MEM_READ) {
151  fatal("[ kn02ba_msr: read from offset 0x%08lx ]\n",
152  (long)relative_addr);
153  } else {
154  fatal("[ kn02ba_msr: write to offset 0x%08lx: 0x%08x ]\n",
155  (long)relative_addr, (int)idata);
156  }
157  exit(1);
158  }
159 
160  if (writeflag == MEM_READ)
161  memory_writemax64(cpu, data, len, odata);
162 
163  return 1;
164 }
165 
166 
167 DEVINIT(kn02ba)
168 {
169  struct kn02ba_data *d;
170  int i;
171 
172  CHECK_ALLOCATION(d = (struct kn02ba_data *) malloc(sizeof(struct kn02ba_data)));
173  memset(d, 0, sizeof(struct kn02ba_data));
174 
175  /* Connect the kn02ba to a specific MIPS CPU interrupt line: */
177 
178  /* Register the interrupts: */
179  for (i = 0; i < 32; i++) {
180  struct interrupt templ;
181  char tmpstr[300];
182  snprintf(tmpstr, sizeof(tmpstr), "%s.kn02ba.0x%x",
183  devinit->interrupt_path, 1 << i);
184  // printf("registering '%s'\n", tmpstr);
185  memset(&templ, 0, sizeof(templ));
186  templ.line = 1 << i;
187  templ.name = tmpstr;
188  templ.extra = d;
192  }
193 
195  KMIN_REG_MER, sizeof(uint32_t), dev_kn02ba_mer_access, d,
196  DM_DEFAULT, NULL);
197 
199  KMIN_REG_MSR, sizeof(uint32_t), dev_kn02ba_msr_access, d,
200  DM_DEFAULT, NULL);
201 
203  devinit->machine->memory, KMIN_SYS_ASIC, 0, &d->irq);
204 
205  d->msr = KMIN_MSR_SIZE_16Mb;
206 
207  return 1;
208 }
209 
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
#define KMIN_REG_MSR
Definition: dec_kmin.h:175
#define KMIN_LASTB15
Definition: dec_kmin.h:219
void fatal(const char *fmt,...)
Definition: main.cc:152
void(* interrupt_assert)(struct interrupt *)
Definition: interrupt.h:38
#define DM_DEFAULT
Definition: memory.h:130
void dec_ioasic_reassert(struct dec_ioasic_data *d)
void kn02ba_interrupt_deassert(struct interrupt *interrupt)
Definition: dev_kn02ba.cc:70
#define KMIN_LASTB31
Definition: dec_kmin.h:217
#define KMIN_SYS_ASIC
Definition: dec_kmin.h:148
void interrupt_handler_register(struct interrupt *templ)
Definition: interrupt.cc:81
#define KMIN_MER_PARDIS
Definition: dec_kmin.h:215
#define MEM_READ
Definition: memory.h:116
void(* interrupt_deassert)(struct interrupt *)
Definition: interrupt.h:39
struct memory * memory
Definition: machine.h:126
uint32_t intr
Definition: devices.h:90
struct dec_ioasic_data * dec_ioasic
Definition: dev_kn02ba.cc:49
#define KMIN_REG_MER
Definition: dec_kmin.h:174
struct cpu ** cpus
Definition: machine.h:140
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239
#define KMIN_MER_TLEN
Definition: dec_kmin.h:214
u_short data
Definition: siireg.h:79
uint32_t msr
Definition: dev_kn02ba.cc:52
#define MEM_WRITE
Definition: memory.h:117
#define KMIN_LASTB07
Definition: dec_kmin.h:220
Definition: device.h:40
struct interrupt irq
Definition: dev_kn02ba.cc:54
#define debug
Definition: dev_adb.cc:57
DEVICE_ACCESS(kn02ba_mer)
Definition: dev_kn02ba.cc:79
uint32_t line
Definition: interrupt.h:51
#define INTERRUPT_CONNECT(name, istruct)
Definition: interrupt.h:77
Definition: cpu.h:326
#define KMIN_LASTB23
Definition: dec_kmin.h:218
struct machine * machine
Definition: device.h:41
char * name
Definition: interrupt.h:66
uint32_t mer
Definition: dev_kn02ba.cc:51
void kn02ba_interrupt_assert(struct interrupt *interrupt)
Definition: dev_kn02ba.cc:63
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
#define KMIN_MER_PAGE_BRY
Definition: dec_kmin.h:213
DEVINIT(kn02ba)
Definition: dev_kn02ba.cc:167
#define KMIN_MSR_SIZE_16Mb
Definition: dec_kmin.h:223
void * extra
Definition: interrupt.h:59
struct dec_ioasic_data * dev_dec_ioasic_init(struct cpu *cpu, struct memory *mem, uint64_t baseaddr, int rackmount_flag, struct interrupt *irqp)
char * interrupt_path
Definition: device.h:50

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13