Coverage Report

Created: 2026-10-31 08:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/hw/ipack/tpci200.c
Line
Count
Source
1
/*
2
 * QEMU TEWS TPCI200 IndustryPack carrier emulation
3
 *
4
 * Copyright (C) 2012 Igalia, S.L.
5
 * Author: Alberto Garcia <berto@igalia.com>
6
 *
7
 * This code is licensed under the GNU GPL v2 or (at your option) any
8
 * later version.
9
 */
10
11
#include "qemu/osdep.h"
12
#include "qemu/units.h"
13
#include "hw/ipack/ipack.h"
14
#include "hw/core/irq.h"
15
#include "hw/pci/pci_device.h"
16
#include "migration/vmstate.h"
17
#include "qemu/bitops.h"
18
#include "qemu/module.h"
19
#include "qom/object.h"
20
21
/* #define DEBUG_TPCI */
22
23
#ifdef DEBUG_TPCI
24
#define DPRINTF(fmt, ...) \
25
    do { fprintf(stderr, "TPCI200: " fmt, ## __VA_ARGS__); } while (0)
26
#else
27
0
#define DPRINTF(fmt, ...) do { } while (0)
28
#endif
29
30
0
#define N_MODULES 4
31
32
0
#define IP_ID_SPACE  2
33
0
#define IP_INT_SPACE 3
34
0
#define IP_IO_SPACE_ADDR_MASK  0x7F
35
0
#define IP_ID_SPACE_ADDR_MASK  0x3F
36
0
#define IP_INT_SPACE_ADDR_MASK 0x3F
37
38
0
#define STATUS_INT(IP, INTNO) BIT((IP) * 2 + (INTNO))
39
0
#define STATUS_TIME(IP)       BIT((IP) + 12)
40
0
#define STATUS_ERR_ANY        0xF00
41
42
#define CTRL_CLKRATE          BIT(0)
43
#define CTRL_RECOVER          BIT(1)
44
#define CTRL_TIME_INT         BIT(2)
45
#define CTRL_ERR_INT          BIT(3)
46
0
#define CTRL_INT_EDGE(INTNO)  BIT(4 + (INTNO))
47
0
#define CTRL_INT(INTNO)       BIT(6 + (INTNO))
48
49
0
#define REG_REV_ID    0x00
50
0
#define REG_IP_A_CTRL 0x02
51
0
#define REG_IP_B_CTRL 0x04
52
0
#define REG_IP_C_CTRL 0x06
53
0
#define REG_IP_D_CTRL 0x08
54
0
#define REG_RESET     0x0A
55
0
#define REG_STATUS    0x0C
56
0
#define IP_N_FROM_REG(REG) ((REG) / 2 - 1)
57
58
struct TPCI200State {
59
    PCIDevice dev;
60
    IPackBus bus;
61
    MemoryRegion mmio;
62
    MemoryRegion io;
63
    MemoryRegion las0;
64
    MemoryRegion las1;
65
    MemoryRegion las2;
66
    MemoryRegion las3;
67
    bool big_endian[3];
68
    uint8_t ctrl[N_MODULES];
69
    uint16_t status;
70
    uint8_t int_set;
71
};
72
73
#define TYPE_TPCI200 "tpci200"
74
75
OBJECT_DECLARE_SIMPLE_TYPE(TPCI200State, TPCI200)
76
77
static const uint8_t local_config_regs[] = {
78
    0x00, 0xFF, 0xFF, 0x0F, 0x00, 0xFC, 0xFF, 0x0F, 0x00, 0x00, 0x00,
79
    0x0E, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
80
    0x00, 0x08, 0x01, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x01,
81
    0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x60, 0x41, 0xD4,
82
    0xA2, 0x20, 0x41, 0x14, 0xA2, 0x20, 0x41, 0x14, 0xA2, 0x20, 0x01,
83
    0x14, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x08, 0x01, 0x02,
84
    0x00, 0x04, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x80, 0x02, 0x41,
85
    0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x00, 0x52, 0x92, 0x24, 0x02
86
};
87
88
static void adjust_addr(bool big_endian, hwaddr *addr, unsigned size)
89
0
{
90
    /* During 8 bit access in big endian mode,
91
       odd and even addresses are swapped */
92
0
    if (big_endian && size == 1) {
93
0
        *addr ^= 1;
94
0
    }
95
0
}
96
97
static uint64_t adjust_value(bool big_endian, uint64_t *val, unsigned size)
98
0
{
99
    /* Local spaces only support 8/16 bit access,
100
     * so there's no need to care for sizes > 2 */
101
0
    if (big_endian && size == 2) {
102
0
        *val = bswap16(*val);
103
0
    }
104
0
    return *val;
105
0
}
106
107
static void tpci200_set_irq(void *opaque, int intno, int level)
108
0
{
109
0
    IPackDevice *ip = opaque;
110
0
    IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(DEVICE(ip)));
111
0
    PCIDevice *pcidev = PCI_DEVICE(BUS(bus)->parent);
112
0
    TPCI200State *dev = TPCI200(pcidev);
113
0
    unsigned ip_n = ip->slot;
114
0
    uint16_t prev_status = dev->status;
115
116
0
    assert(ip->slot >= 0 && ip->slot < N_MODULES);
117
118
    /* The requested interrupt must be enabled in the IP CONTROL
119
     * register */
120
0
    if (!(dev->ctrl[ip_n] & CTRL_INT(intno))) {
121
0
        return;
122
0
    }
123
124
    /* Update the interrupt status in the IP STATUS register */
125
0
    if (level) {
126
0
        dev->status |=  STATUS_INT(ip_n, intno);
127
0
    } else {
128
0
        dev->status &= ~STATUS_INT(ip_n, intno);
129
0
    }
130
131
    /* Return if there are no changes */
132
0
    if (dev->status == prev_status) {
133
0
        return;
134
0
    }
135
136
0
    DPRINTF("IP %u INT%u#: %u\n", ip_n, intno, level);
137
138
    /* Check if the interrupt is edge sensitive */
139
0
    if (dev->ctrl[ip_n] & CTRL_INT_EDGE(intno)) {
140
0
        if (level) {
141
0
            pci_set_irq(&dev->dev, !dev->int_set);
142
0
            pci_set_irq(&dev->dev,  dev->int_set);
143
0
        }
144
0
    } else {
145
0
        unsigned i, j;
146
0
        uint16_t level_status = dev->status;
147
148
        /* Check if there are any level sensitive interrupts set by
149
           removing the ones that are edge sensitive from the status
150
           register */
151
0
        for (i = 0; i < N_MODULES; i++) {
152
0
            for (j = 0; j < 2; j++) {
153
0
                if (dev->ctrl[i] & CTRL_INT_EDGE(j)) {
154
0
                    level_status &= ~STATUS_INT(i, j);
155
0
                }
156
0
            }
157
0
        }
158
159
0
        if (level_status && !dev->int_set) {
160
0
            pci_irq_assert(&dev->dev);
161
0
            dev->int_set = 1;
162
0
        } else if (!level_status && dev->int_set) {
163
0
            pci_irq_deassert(&dev->dev);
164
0
            dev->int_set = 0;
165
0
        }
166
0
    }
167
0
}
168
169
static uint64_t tpci200_read_cfg(void *opaque, hwaddr addr, unsigned size)
170
0
{
171
0
    TPCI200State *s = opaque;
172
0
    uint8_t ret = 0;
173
0
    if (addr < ARRAY_SIZE(local_config_regs)) {
174
0
        ret = local_config_regs[addr];
175
0
    }
176
    /* Endianness is stored in the first bit of these registers */
177
0
    if ((addr == 0x2b && s->big_endian[0]) ||
178
0
        (addr == 0x2f && s->big_endian[1]) ||
179
0
        (addr == 0x33 && s->big_endian[2])) {
180
0
        ret |= 1;
181
0
    }
182
0
    DPRINTF("Read from LCR 0x%x: 0x%x\n", (unsigned) addr, (unsigned) ret);
183
0
    return ret;
184
0
}
185
186
static void tpci200_write_cfg(void *opaque, hwaddr addr, uint64_t val,
187
                              unsigned size)
188
0
{
189
0
    TPCI200State *s = opaque;
190
    /* Endianness is stored in the first bit of these registers */
191
0
    if (addr == 0x2b || addr == 0x2f || addr == 0x33) {
192
0
        unsigned las = (addr - 0x2b) / 4;
193
0
        s->big_endian[las] = val & 1;
194
0
        DPRINTF("LAS%u big endian mode: %u\n", las, (unsigned) val & 1);
195
0
    } else {
196
0
        DPRINTF("Write to LCR 0x%x: 0x%x\n", (unsigned) addr, (unsigned) val);
197
0
    }
198
0
}
199
200
static uint64_t tpci200_read_las0(void *opaque, hwaddr addr, unsigned size)
201
0
{
202
0
    TPCI200State *s = opaque;
203
0
    uint64_t ret = 0;
204
205
0
    switch (addr) {
206
207
0
    case REG_REV_ID:
208
0
        DPRINTF("Read REVISION ID\n"); /* Current value is 0x00 */
209
0
        break;
210
211
0
    case REG_IP_A_CTRL:
212
0
    case REG_IP_B_CTRL:
213
0
    case REG_IP_C_CTRL:
214
0
    case REG_IP_D_CTRL:
215
0
        {
216
0
            unsigned ip_n = IP_N_FROM_REG(addr);
217
0
            ret = s->ctrl[ip_n];
218
0
            DPRINTF("Read IP %c CONTROL: 0x%x\n", 'A' + ip_n, (unsigned) ret);
219
0
        }
220
0
        break;
221
222
0
    case REG_RESET:
223
0
        DPRINTF("Read RESET\n"); /* Not implemented */
224
0
        break;
225
226
0
    case REG_STATUS:
227
0
        ret = s->status;
228
0
        DPRINTF("Read STATUS: 0x%x\n", (unsigned) ret);
229
0
        break;
230
231
    /* Reserved */
232
0
    default:
233
0
        DPRINTF("Unsupported read from LAS0 0x%x\n", (unsigned) addr);
234
0
        break;
235
0
    }
236
237
0
    return adjust_value(s->big_endian[0], &ret, size);
238
0
}
239
240
static void tpci200_write_las0(void *opaque, hwaddr addr, uint64_t val,
241
                               unsigned size)
242
0
{
243
0
    TPCI200State *s = opaque;
244
245
0
    adjust_value(s->big_endian[0], &val, size);
246
247
0
    switch (addr) {
248
249
0
    case REG_REV_ID:
250
0
        DPRINTF("Write Revision ID: 0x%x\n", (unsigned) val); /* No effect */
251
0
        break;
252
253
0
    case REG_IP_A_CTRL:
254
0
    case REG_IP_B_CTRL:
255
0
    case REG_IP_C_CTRL:
256
0
    case REG_IP_D_CTRL:
257
0
        {
258
0
            unsigned ip_n = IP_N_FROM_REG(addr);
259
0
            s->ctrl[ip_n] = val;
260
0
            DPRINTF("Write IP %c CONTROL: 0x%x\n", 'A' + ip_n, (unsigned) val);
261
0
        }
262
0
        break;
263
264
0
    case REG_RESET:
265
0
        DPRINTF("Write RESET: 0x%x\n", (unsigned) val); /* Not implemented */
266
0
        break;
267
268
0
    case REG_STATUS:
269
0
        {
270
0
            unsigned i;
271
272
0
            for (i = 0; i < N_MODULES; i++) {
273
0
                IPackDevice *ip = ipack_device_find(&s->bus, i);
274
275
0
                if (ip != NULL) {
276
0
                    if (val & STATUS_INT(i, 0)) {
277
0
                        DPRINTF("Clear IP %c INT0# status\n", 'A' + i);
278
0
                        qemu_irq_lower(&ip->irq[0]);
279
0
                    }
280
0
                    if (val & STATUS_INT(i, 1)) {
281
0
                        DPRINTF("Clear IP %c INT1# status\n", 'A' + i);
282
0
                        qemu_irq_lower(&ip->irq[1]);
283
0
                    }
284
0
                }
285
286
0
                if (val & STATUS_TIME(i)) {
287
0
                    DPRINTF("Clear IP %c timeout\n", 'A' + i);
288
0
                    s->status &= ~STATUS_TIME(i);
289
0
                }
290
0
            }
291
292
0
            if (val & STATUS_ERR_ANY) {
293
0
                DPRINTF("Unexpected write to STATUS register: 0x%x\n",
294
0
                        (unsigned) val);
295
0
            }
296
0
        }
297
0
        break;
298
299
    /* Reserved */
300
0
    default:
301
0
        DPRINTF("Unsupported write to LAS0 0x%x: 0x%x\n",
302
0
                (unsigned) addr, (unsigned) val);
303
0
        break;
304
0
    }
305
0
}
306
307
static uint64_t tpci200_read_las1(void *opaque, hwaddr addr, unsigned size)
308
0
{
309
0
    TPCI200State *s = opaque;
310
0
    IPackDevice *ip;
311
0
    uint64_t ret = 0;
312
0
    unsigned ip_n, space;
313
0
    uint8_t offset;
314
315
0
    adjust_addr(s->big_endian[1], &addr, size);
316
317
    /*
318
     * The address is divided into the IP module number (0-4), the IP
319
     * address space (I/O, ID, INT) and the offset within that space.
320
     */
321
0
    ip_n = addr >> 8;
322
0
    space = (addr >> 6) & 3;
323
0
    ip = ipack_device_find(&s->bus, ip_n);
324
325
0
    if (ip == NULL) {
326
0
        DPRINTF("Read LAS1: IP module %u not installed\n", ip_n);
327
0
    } else {
328
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
329
0
        switch (space) {
330
331
0
        case IP_ID_SPACE:
332
0
            offset = addr & IP_ID_SPACE_ADDR_MASK;
333
0
            if (k->id_read) {
334
0
                ret = k->id_read(ip, offset);
335
0
            }
336
0
            break;
337
338
0
        case IP_INT_SPACE:
339
0
            offset = addr & IP_INT_SPACE_ADDR_MASK;
340
341
            /* Read address 0 to ACK IP INT0# and address 2 to ACK IP INT1# */
342
0
            if (offset == 0 || offset == 2) {
343
0
                unsigned intno = offset / 2;
344
0
                bool int_set = s->status & STATUS_INT(ip_n, intno);
345
0
                bool int_edge_sensitive = s->ctrl[ip_n] & CTRL_INT_EDGE(intno);
346
0
                if (int_set && !int_edge_sensitive) {
347
0
                    qemu_irq_lower(&ip->irq[intno]);
348
0
                }
349
0
            }
350
351
0
            if (k->int_read) {
352
0
                ret = k->int_read(ip, offset);
353
0
            }
354
0
            break;
355
356
0
        default:
357
0
            offset = addr & IP_IO_SPACE_ADDR_MASK;
358
0
            if (k->io_read) {
359
0
                ret = k->io_read(ip, offset);
360
0
            }
361
0
            break;
362
0
        }
363
0
    }
364
365
0
    return adjust_value(s->big_endian[1], &ret, size);
366
0
}
367
368
static void tpci200_write_las1(void *opaque, hwaddr addr, uint64_t val,
369
                               unsigned size)
370
0
{
371
0
    TPCI200State *s = opaque;
372
0
    IPackDevice *ip;
373
0
    unsigned ip_n, space;
374
0
    uint8_t offset;
375
376
0
    adjust_addr(s->big_endian[1], &addr, size);
377
0
    adjust_value(s->big_endian[1], &val, size);
378
379
    /*
380
     * The address is divided into the IP module number, the IP
381
     * address space (I/O, ID, INT) and the offset within that space.
382
     */
383
0
    ip_n = addr >> 8;
384
0
    space = (addr >> 6) & 3;
385
0
    ip = ipack_device_find(&s->bus, ip_n);
386
387
0
    if (ip == NULL) {
388
0
        DPRINTF("Write LAS1: IP module %u not installed\n", ip_n);
389
0
    } else {
390
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
391
0
        switch (space) {
392
393
0
        case IP_ID_SPACE:
394
0
            offset = addr & IP_ID_SPACE_ADDR_MASK;
395
0
            if (k->id_write) {
396
0
                k->id_write(ip, offset, val);
397
0
            }
398
0
            break;
399
400
0
        case IP_INT_SPACE:
401
0
            offset = addr & IP_INT_SPACE_ADDR_MASK;
402
0
            if (k->int_write) {
403
0
                k->int_write(ip, offset, val);
404
0
            }
405
0
            break;
406
407
0
        default:
408
0
            offset = addr & IP_IO_SPACE_ADDR_MASK;
409
0
            if (k->io_write) {
410
0
                k->io_write(ip, offset, val);
411
0
            }
412
0
            break;
413
0
        }
414
0
    }
415
0
}
416
417
static uint64_t tpci200_read_las2(void *opaque, hwaddr addr, unsigned size)
418
0
{
419
0
    TPCI200State *s = opaque;
420
0
    IPackDevice *ip;
421
0
    uint64_t ret = 0;
422
0
    unsigned ip_n;
423
0
    uint32_t offset;
424
425
0
    adjust_addr(s->big_endian[2], &addr, size);
426
427
    /*
428
     * The address is divided into the IP module number and the offset
429
     * within the IP module MEM space.
430
     */
431
0
    ip_n = addr >> 23;
432
0
    offset = addr & 0x7fffff;
433
0
    ip = ipack_device_find(&s->bus, ip_n);
434
435
0
    if (ip == NULL) {
436
0
        DPRINTF("Read LAS2: IP module %u not installed\n", ip_n);
437
0
    } else {
438
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
439
0
        if (k->mem_read16) {
440
0
            ret = k->mem_read16(ip, offset);
441
0
        }
442
0
    }
443
444
0
    return adjust_value(s->big_endian[2], &ret, size);
445
0
}
446
447
static void tpci200_write_las2(void *opaque, hwaddr addr, uint64_t val,
448
                               unsigned size)
449
0
{
450
0
    TPCI200State *s = opaque;
451
0
    IPackDevice *ip;
452
0
    unsigned ip_n;
453
0
    uint32_t offset;
454
455
0
    adjust_addr(s->big_endian[2], &addr, size);
456
0
    adjust_value(s->big_endian[2], &val, size);
457
458
    /*
459
     * The address is divided into the IP module number and the offset
460
     * within the IP module MEM space.
461
     */
462
0
    ip_n = addr >> 23;
463
0
    offset = addr & 0x7fffff;
464
0
    ip = ipack_device_find(&s->bus, ip_n);
465
466
0
    if (ip == NULL) {
467
0
        DPRINTF("Write LAS2: IP module %u not installed\n", ip_n);
468
0
    } else {
469
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
470
0
        if (k->mem_write16) {
471
0
            k->mem_write16(ip, offset, val);
472
0
        }
473
0
    }
474
0
}
475
476
static uint64_t tpci200_read_las3(void *opaque, hwaddr addr, unsigned size)
477
0
{
478
0
    TPCI200State *s = opaque;
479
0
    IPackDevice *ip;
480
0
    uint64_t ret = 0;
481
    /*
482
     * The address is divided into the IP module number and the offset
483
     * within the IP module MEM space.
484
     */
485
0
    unsigned ip_n = addr >> 22;
486
0
    uint32_t offset = addr & 0x3fffff;
487
488
0
    ip = ipack_device_find(&s->bus, ip_n);
489
490
0
    if (ip == NULL) {
491
0
        DPRINTF("Read LAS3: IP module %u not installed\n", ip_n);
492
0
    } else {
493
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
494
0
        if (k->mem_read8) {
495
0
            ret = k->mem_read8(ip, offset);
496
0
        }
497
0
    }
498
499
0
    return ret;
500
0
}
501
502
static void tpci200_write_las3(void *opaque, hwaddr addr, uint64_t val,
503
                               unsigned size)
504
0
{
505
0
    TPCI200State *s = opaque;
506
0
    IPackDevice *ip;
507
    /*
508
     * The address is divided into the IP module number and the offset
509
     * within the IP module MEM space.
510
     */
511
0
    unsigned ip_n = addr >> 22;
512
0
    uint32_t offset = addr & 0x3fffff;
513
514
0
    ip = ipack_device_find(&s->bus, ip_n);
515
516
0
    if (ip == NULL) {
517
0
        DPRINTF("Write LAS3: IP module %u not installed\n", ip_n);
518
0
    } else {
519
0
        IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(ip);
520
0
        if (k->mem_write8) {
521
0
            k->mem_write8(ip, offset, val);
522
0
        }
523
0
    }
524
0
}
525
526
static const MemoryRegionOps tpci200_cfg_ops = {
527
    .read = tpci200_read_cfg,
528
    .write = tpci200_write_cfg,
529
    .endianness = DEVICE_NATIVE_ENDIAN,
530
    .valid =  {
531
        .min_access_size = 1,
532
        .max_access_size = 4
533
    },
534
    .impl = {
535
        .min_access_size = 1,
536
        .max_access_size = 1
537
    }
538
};
539
540
static const MemoryRegionOps tpci200_las0_ops = {
541
    .read = tpci200_read_las0,
542
    .write = tpci200_write_las0,
543
    .endianness = DEVICE_NATIVE_ENDIAN,
544
    .valid =  {
545
        .min_access_size = 2,
546
        .max_access_size = 2
547
    }
548
};
549
550
static const MemoryRegionOps tpci200_las1_ops = {
551
    .read = tpci200_read_las1,
552
    .write = tpci200_write_las1,
553
    .endianness = DEVICE_NATIVE_ENDIAN,
554
    .valid =  {
555
        .min_access_size = 1,
556
        .max_access_size = 2
557
    }
558
};
559
560
static const MemoryRegionOps tpci200_las2_ops = {
561
    .read = tpci200_read_las2,
562
    .write = tpci200_write_las2,
563
    .endianness = DEVICE_NATIVE_ENDIAN,
564
    .valid =  {
565
        .min_access_size = 1,
566
        .max_access_size = 2
567
    }
568
};
569
570
static const MemoryRegionOps tpci200_las3_ops = {
571
    .read = tpci200_read_las3,
572
    .write = tpci200_write_las3,
573
    .endianness = DEVICE_NATIVE_ENDIAN,
574
    .valid =  {
575
        .min_access_size = 1,
576
        .max_access_size = 1
577
    }
578
};
579
580
static void tpci200_realize(PCIDevice *pci_dev, Error **errp)
581
0
{
582
0
    TPCI200State *s = TPCI200(pci_dev);
583
0
    uint8_t *c = s->dev.config;
584
585
0
    pci_set_word(c + PCI_COMMAND, 0x0003);
586
0
    pci_set_word(c + PCI_STATUS,  0x0280);
587
588
0
    pci_set_byte(c + PCI_INTERRUPT_PIN, 0x01); /* Interrupt pin A */
589
590
0
    pci_set_byte(c + PCI_CAPABILITY_LIST, 0x40);
591
0
    pci_set_long(c + 0x40, 0x48014801);
592
0
    pci_set_long(c + 0x48, 0x00024C06);
593
0
    pci_set_long(c + 0x4C, 0x00000003);
594
595
0
    memory_region_init_io(&s->mmio, OBJECT(s), &tpci200_cfg_ops,
596
0
                          s, "tpci200_mmio", 128);
597
0
    memory_region_init_io(&s->io, OBJECT(s),   &tpci200_cfg_ops,
598
0
                          s, "tpci200_io",   128);
599
0
    memory_region_init_io(&s->las0, OBJECT(s), &tpci200_las0_ops,
600
0
                          s, "tpci200_las0", 256);
601
0
    memory_region_init_io(&s->las1, OBJECT(s), &tpci200_las1_ops,
602
0
                          s, "tpci200_las1", 1024);
603
0
    memory_region_init_io(&s->las2, OBJECT(s), &tpci200_las2_ops,
604
0
                          s, "tpci200_las2", 32 * MiB);
605
0
    memory_region_init_io(&s->las3, OBJECT(s), &tpci200_las3_ops,
606
0
                          s, "tpci200_las3", 16 * MiB);
607
0
    pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
608
0
    pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO,     &s->io);
609
0
    pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las0);
610
0
    pci_register_bar(&s->dev, 3, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las1);
611
0
    pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las2);
612
0
    pci_register_bar(&s->dev, 5, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->las3);
613
614
0
    ipack_bus_init(&s->bus, sizeof(s->bus), DEVICE(pci_dev),
615
0
                   N_MODULES, tpci200_set_irq);
616
0
}
617
618
static const VMStateDescription vmstate_tpci200 = {
619
    .name = "tpci200",
620
    .version_id = 1,
621
    .minimum_version_id = 1,
622
    .fields = (const VMStateField[]) {
623
        VMSTATE_PCI_DEVICE(dev, TPCI200State),
624
        VMSTATE_BOOL_ARRAY(big_endian, TPCI200State, 3),
625
        VMSTATE_UINT8_ARRAY(ctrl, TPCI200State, N_MODULES),
626
        VMSTATE_UINT16(status, TPCI200State),
627
        VMSTATE_UINT8(int_set, TPCI200State),
628
        VMSTATE_END_OF_LIST()
629
    }
630
};
631
632
static void tpci200_class_init(ObjectClass *klass, const void *data)
633
61
{
634
61
    DeviceClass *dc = DEVICE_CLASS(klass);
635
61
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
636
637
61
    k->realize = tpci200_realize;
638
61
    k->vendor_id = PCI_VENDOR_ID_TEWS;
639
61
    k->device_id = PCI_DEVICE_ID_TEWS_TPCI200;
640
61
    k->class_id = PCI_CLASS_BRIDGE_OTHER;
641
61
    k->subsystem_vendor_id = PCI_VENDOR_ID_TEWS;
642
61
    k->subsystem_id = 0x300A;
643
61
    set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
644
61
    dc->desc = "TEWS TPCI200 IndustryPack carrier";
645
61
    dc->vmsd = &vmstate_tpci200;
646
61
}
647
648
static const TypeInfo tpci200_info = {
649
    .name          = TYPE_TPCI200,
650
    .parent        = TYPE_PCI_DEVICE,
651
    .instance_size = sizeof(TPCI200State),
652
    .class_init    = tpci200_class_init,
653
    .interfaces = (const InterfaceInfo[]) {
654
        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
655
        { },
656
    },
657
};
658
659
static void tpci200_register_types(void)
660
61
{
661
61
    type_register_static(&tpci200_info);
662
61
}
663
664
type_init(tpci200_register_types)