/[gxemul]/trunk/src/devices/dev_kn230.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_kn230.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_kn230.c,v 1.15 2006/02/09 20:02:59 debug Exp $   *  $Id: dev_kn230.c,v 1.18 2007/02/03 20:14:23 debug Exp $
29   *     *  
30   *  DEC MIPSMATE 5100 (KN230) stuff.   *  DEC MIPSMATE 5100 (KN230) stuff.
31   */   */
# Line 35  Line 35 
35  #include <string.h>  #include <string.h>
36    
37  #include "device.h"  #include "device.h"
38  #include "devices.h"  #include "interrupt.h"
39  #include "machine.h"  #include "machine.h"
40  #include "memory.h"  #include "memory.h"
41  #include "misc.h"  #include "misc.h"
42    
43    #include "dec_5100.h"
44    
45    
46  #define DEV_KN230_LENGTH                0x1c00000  #define DEV_KN230_LENGTH                0x1c00000
47    
48    struct kn230_data {
49            struct interrupt        mips_irq_2;
50            struct interrupt        mips_irq_3;
51    
52  /*          uint32_t                csr;
53   *  dev_kn230_access():  };
54    
55    
56    /*  
57     *  kn230_interrupt_assert():
58     *  kn230_interrupt_deassert():
59     *
60     *  Called whenever a KN230 interrupt is asserted/deasserted.
61   */   */
62    void kn230_interrupt_assert(struct interrupt *interrupt)
63    {
64            struct kn230_data *d = interrupt->extra;
65            int assert2 = 0, assert3 = 0;
66    
67            d->csr |= interrupt->line;
68            if (d->csr & (KN230_CSR_INTR_SII | KN230_CSR_INTR_LANCE))
69                    assert3 = 1;
70            if (d->csr & (KN230_CSR_INTR_DZ0 |
71                KN230_CSR_INTR_OPT0 | KN230_CSR_INTR_OPT1))
72                    assert2 = 1;
73    
74            if (assert2)
75                    INTERRUPT_ASSERT(d->mips_irq_2);
76            if (assert3)
77                    INTERRUPT_ASSERT(d->mips_irq_2);
78    }
79    void kn230_interrupt_deassert(struct interrupt *interrupt)
80    {
81            struct kn230_data *d = interrupt->extra;
82            int assert2 = 0, assert3 = 0;
83    
84            d->csr &= ~interrupt->line;
85            if (d->csr & (KN230_CSR_INTR_SII | KN230_CSR_INTR_LANCE))
86                    assert3 = 1;
87            if (d->csr & (KN230_CSR_INTR_DZ0 |
88                KN230_CSR_INTR_OPT0 | KN230_CSR_INTR_OPT1))
89                    assert2 = 1;
90    
91            if (!assert2)
92                    INTERRUPT_DEASSERT(d->mips_irq_2);
93            if (!assert3)
94                    INTERRUPT_DEASSERT(d->mips_irq_2);
95    }
96    
97    
98  DEVICE_ACCESS(kn230)  DEVICE_ACCESS(kn230)
99  {  {
100          struct kn230_csr *d = extra;          struct kn230_data *d = extra;
101          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
102    
103          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 85  DEVICE_ACCESS(kn230) Line 133  DEVICE_ACCESS(kn230)
133    
134  DEVINIT(kn230)  DEVINIT(kn230)
135  {  {
136          struct kn230_csr *d;          struct kn230_data *d;
137            char tmpstr[300];
138            int i;
139    
140          d = malloc(sizeof(struct kn230_csr));          d = malloc(sizeof(struct kn230_data));
141          if (d == NULL) {          if (d == NULL) {
142                  fprintf(stderr, "out of memory\n");                  fprintf(stderr, "out of memory\n");
143                  exit(1);                  exit(1);
144          }          }
145          memset(d, 0, sizeof(struct kn230_csr));          memset(d, 0, sizeof(struct kn230_data));
146    
147            /*
148             *  devinit->interrupt_path points to the MIPS cpu itself.
149             *  The KN230 interrupt controller interrupts at MIPS interrupts
150             *  2 and 3, depending on which KN230 is asserted.
151             */
152            snprintf(tmpstr, sizeof(tmpstr), "%s.2", devinit->interrupt_path);
153            INTERRUPT_CONNECT(tmpstr, d->mips_irq_2);
154            snprintf(tmpstr, sizeof(tmpstr), "%s.3", devinit->interrupt_path);
155            INTERRUPT_CONNECT(tmpstr, d->mips_irq_3);
156    
157            /*  Register KN230 interrupts 8..15:  */
158            for (i=8; i<=15; i++) {
159                    struct interrupt template;
160                    char tmpstr[300];
161                    snprintf(tmpstr, sizeof(tmpstr), "%s.kn230.0x%x",
162                        devinit->interrupt_path, 1 << i);
163                    memset(&template, 0, sizeof(template));
164                    template.line = 1 << i;
165                    template.name = tmpstr;
166                    template.extra = d;
167                    template.interrupt_assert = kn230_interrupt_assert;
168                    template.interrupt_deassert = kn230_interrupt_deassert;
169                    interrupt_handler_register(&template);
170            }
171    
172          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,
173              devinit->addr, DEV_KN230_LENGTH, dev_kn230_access, d,              devinit->addr, DEV_KN230_LENGTH, dev_kn230_access, d,

Legend:
Removed from v.22  
changed lines
  Added in v.34

  ViewVC Help
Powered by ViewVC 1.1.26