/[gxemul]/trunk/src/devices/dev_footbridge.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_footbridge.c

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

revision 32 by dpavlin, Mon Oct 8 16:20:58 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-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_footbridge.c,v 1.48 2006/09/30 10:09:19 debug Exp $   *  $Id: dev_footbridge.c,v 1.55 2007/02/03 16:18:56 debug Exp $
29   *   *
30   *  Footbridge. Used in Netwinder and Cats.   *  Footbridge. Used in Netwinder and Cats.
31   *   *
# Line 34  Line 34 
34   *      o)  FIQs.   *      o)  FIQs.
35   *      o)  Pretty much everything else as well :)  (This entire thing   *      o)  Pretty much everything else as well :)  (This entire thing
36   *          is a quick hack to work primarily with NetBSD and OpenBSD   *          is a quick hack to work primarily with NetBSD and OpenBSD
37   *          as a guest OS.)   *          as guest OSes.)
38   */   */
39    
40  #include <stdio.h>  #include <stdio.h>
# Line 57  Line 57 
57  #define DEV_FOOTBRIDGE_TICK_SHIFT       14  #define DEV_FOOTBRIDGE_TICK_SHIFT       14
58  #define DEV_FOOTBRIDGE_LENGTH           0x400  #define DEV_FOOTBRIDGE_LENGTH           0x400
59    
60    #define N_FOOTBRIDGE_TIMERS             4
61    
62    struct footbridge_data {
63            struct interrupt irq;
64    
65            struct pci_data *pcibus;
66    
67            int             console_handle;
68    
69            uint32_t        timer_load[N_FOOTBRIDGE_TIMERS];
70            uint32_t        timer_value[N_FOOTBRIDGE_TIMERS];
71            uint32_t        timer_control[N_FOOTBRIDGE_TIMERS];
72    
73            struct interrupt timer_irq[N_FOOTBRIDGE_TIMERS];
74            struct timer    *timer[N_FOOTBRIDGE_TIMERS];
75            int             pending_timer_interrupts[N_FOOTBRIDGE_TIMERS];
76    
77            int             irq_asserted;
78    
79            uint32_t        irq_status;
80            uint32_t        irq_enable;
81    
82            uint32_t        fiq_status;
83            uint32_t        fiq_enable;
84    };
85    
86    
87  static void timer_tick0(struct timer *t, void *extra)  static void timer_tick0(struct timer *t, void *extra)
88  { ((struct footbridge_data *)extra)->pending_timer_interrupts[0] ++; }  { ((struct footbridge_data *)extra)->pending_timer_interrupts[0] ++; }
# Line 81  static void reload_timer_value(struct cp Line 107  static void reload_timer_value(struct cp
107          freq /= (double)cycles;          freq /= (double)cycles;
108    
109          d->timer_value[timer_nr] = d->timer_load[timer_nr];          d->timer_value[timer_nr] = d->timer_load[timer_nr];
         d->timer_tick_countdown[timer_nr] = 1;  
110    
111          /*  printf("%i: %i -> %f Hz\n", timer_nr,          /*  printf("%i: %i -> %f Hz\n", timer_nr,
112              d->timer_load[timer_nr], freq);  */              d->timer_load[timer_nr], freq);  */
# Line 118  void dev_footbridge_tick(struct cpu *cpu Line 143  void dev_footbridge_tick(struct cpu *cpu
143                  if (d->timer_control[i] & TIMER_ENABLE) {                  if (d->timer_control[i] & TIMER_ENABLE) {
144                          if (d->pending_timer_interrupts[i] > 0) {                          if (d->pending_timer_interrupts[i] > 0) {
145                                  d->timer_value[i] = random() % d->timer_load[i];                                  d->timer_value[i] = random() % d->timer_load[i];
146                                  cpu_interrupt(cpu, IRQ_TIMER_1 + i);                                  INTERRUPT_ASSERT(d->timer_irq[i]);
147                          }                          }
148                  }                  }
149          }          }
# Line 126  void dev_footbridge_tick(struct cpu *cpu Line 151  void dev_footbridge_tick(struct cpu *cpu
151    
152    
153  /*  /*
154     *  footbridge_interrupt_assert():
155     */
156    void footbridge_interrupt_assert(struct interrupt *interrupt)
157    {
158            struct footbridge_data *d = (struct footbridge_data *) interrupt->extra;
159            d->irq_status |= interrupt->line;
160    
161            if ((d->irq_status & d->irq_enable) && !d->irq_asserted) {
162                    d->irq_asserted = 1;
163                    INTERRUPT_ASSERT(d->irq);
164            }
165    }
166    
167    
168    /*
169     *  footbridge_interrupt_deassert():
170     */
171    void footbridge_interrupt_deassert(struct interrupt *interrupt)
172    {
173            struct footbridge_data *d = (struct footbridge_data *) interrupt->extra;
174            d->irq_status &= ~interrupt->line;
175    
176            if (!(d->irq_status & d->irq_enable) && d->irq_asserted) {
177                    d->irq_asserted = 0;
178                    INTERRUPT_DEASSERT(d->irq);
179            }
180    }
181    
182    
183    /*
184   *  dev_footbridge_isa_access():   *  dev_footbridge_isa_access():
185   *   *
186   *  Reading the byte at 0x79000000 is a quicker way to figure out which ISA   *  Reading the byte at 0x79000000 is a quicker way to figure out which ISA
# Line 144  DEVICE_ACCESS(footbridge_isa) Line 199  DEVICE_ACCESS(footbridge_isa)
199          }          }
200    
201          x = cpu->machine->isa_pic_data.last_int;          x = cpu->machine->isa_pic_data.last_int;
         if (x == 0)  
                 cpu_interrupt_ack(cpu, 32 + x);  
   
202          if (x < 8)          if (x < 8)
203                  odata = cpu->machine->isa_pic_data.pic1->irq_base + x;                  odata = cpu->machine->isa_pic_data.pic1->irq_base + x;
204          else          else
# Line 309  DEVICE_ACCESS(footbridge) Line 361  DEVICE_ACCESS(footbridge)
361          case IRQ_ENABLE_SET:          case IRQ_ENABLE_SET:
362                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
363                          d->irq_enable |= idata;                          d->irq_enable |= idata;
364                          cpu_interrupt(cpu, 64);                          if (d->irq_status & d->irq_enable)
365                                    INTERRUPT_ASSERT(d->irq);
366                            else
367                                    INTERRUPT_DEASSERT(d->irq);
368                  } else {                  } else {
369                          odata = d->irq_enable;                          odata = d->irq_enable;
370                          fatal("[ WARNING: footbridge read from "                          fatal("[ WARNING: footbridge read from "
# Line 321  DEVICE_ACCESS(footbridge) Line 376  DEVICE_ACCESS(footbridge)
376          case IRQ_ENABLE_CLEAR:          case IRQ_ENABLE_CLEAR:
377                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
378                          d->irq_enable &= ~idata;                          d->irq_enable &= ~idata;
379                          cpu_interrupt(cpu, 64);                          if (d->irq_status & d->irq_enable)
380                                    INTERRUPT_ASSERT(d->irq);
381                            else
382                                    INTERRUPT_DEASSERT(d->irq);
383                  } else {                  } else {
384                          odata = d->irq_enable;                          odata = d->irq_enable;
385                          fatal("[ WARNING: footbridge read from "                          fatal("[ WARNING: footbridge read from "
# Line 367  DEVICE_ACCESS(footbridge) Line 425  DEVICE_ACCESS(footbridge)
425                          /*  debug("[ footbridge: timer %i (1-based), "                          /*  debug("[ footbridge: timer %i (1-based), "
426                              "value %i ]\n", timer_nr + 1,                              "value %i ]\n", timer_nr + 1,
427                              (int)d->timer_value[timer_nr]);  */                              (int)d->timer_value[timer_nr]);  */
428                          cpu_interrupt_ack(cpu, IRQ_TIMER_1 + timer_nr);                          INTERRUPT_DEASSERT(d->timer_irq[timer_nr]);
429                  }                  }
430                  break;                  break;
431    
# Line 394  DEVICE_ACCESS(footbridge) Line 452  DEVICE_ACCESS(footbridge)
452                          } else {                          } else {
453                                  d->pending_timer_interrupts[timer_nr] = 0;                                  d->pending_timer_interrupts[timer_nr] = 0;
454                          }                          }
455                          cpu_interrupt_ack(cpu, IRQ_TIMER_1 + timer_nr);                          INTERRUPT_DEASSERT(d->timer_irq[timer_nr]);
456                  }                  }
457                  break;                  break;
458    
# Line 407  DEVICE_ACCESS(footbridge) Line 465  DEVICE_ACCESS(footbridge)
465                          d->pending_timer_interrupts[timer_nr] --;                          d->pending_timer_interrupts[timer_nr] --;
466                  }                  }
467    
468                  cpu_interrupt_ack(cpu, IRQ_TIMER_1 + timer_nr);                  INTERRUPT_DEASSERT(d->timer_irq[timer_nr]);
469                  break;                  break;
470    
471          default:if (writeflag == MEM_READ) {          default:if (writeflag == MEM_READ) {
# Line 429  DEVICE_ACCESS(footbridge) Line 487  DEVICE_ACCESS(footbridge)
487  DEVINIT(footbridge)  DEVINIT(footbridge)
488  {  {
489          struct footbridge_data *d;          struct footbridge_data *d;
490            char irq_path[300], irq_path_isa[300];
491          uint64_t pci_addr = 0x7b000000;          uint64_t pci_addr = 0x7b000000;
492          int i;          int i;
493    
# Line 439  DEVINIT(footbridge) Line 498  DEVINIT(footbridge)
498          }          }
499          memset(d, 0, sizeof(struct footbridge_data));          memset(d, 0, sizeof(struct footbridge_data));
500    
501            /*  Connect to the CPU which this footbridge will interrupt:  */
502            INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
503    
504          /*  DC21285 register access:  */          /*  DC21285 register access:  */
505          memory_device_register(devinit->machine->memory, devinit->name,          memory_device_register(devinit->machine->memory, devinit->name,
506              devinit->addr, DEV_FOOTBRIDGE_LENGTH,              devinit->addr, DEV_FOOTBRIDGE_LENGTH,
# Line 451  DEVINIT(footbridge) Line 513  DEVINIT(footbridge)
513          /*  The "fcom" console:  */          /*  The "fcom" console:  */
514          d->console_handle = console_start_slave(devinit->machine, "fcom", 0);          d->console_handle = console_start_slave(devinit->machine, "fcom", 0);
515    
516            /*  Register 32 footbridge interrupts:  */
517            snprintf(irq_path, sizeof(irq_path), "%s.footbridge",
518                devinit->interrupt_path);
519            for (i=0; i<32; i++) {
520                    struct interrupt interrupt_template;
521                    char tmpstr[200];
522    
523                    memset(&interrupt_template, 0, sizeof(interrupt_template));
524                    interrupt_template.line = 1 << i;
525                    snprintf(tmpstr, sizeof(tmpstr), "%s.%i", irq_path, i);
526                    interrupt_template.name = tmpstr;
527    
528                    interrupt_template.extra = d;
529                    interrupt_template.interrupt_assert =
530                        footbridge_interrupt_assert;
531                    interrupt_template.interrupt_deassert =
532                        footbridge_interrupt_deassert;
533                    interrupt_handler_register(&interrupt_template);
534    
535                    /*  Connect locally to some interrupts:  */
536                    if (i>=IRQ_TIMER_1 && i<=IRQ_TIMER_4)
537                            INTERRUPT_CONNECT(tmpstr, d->timer_irq[i-IRQ_TIMER_1]);
538            }
539    
540            switch (devinit->machine->machine_type) {
541            case MACHINE_CATS:
542                    snprintf(irq_path_isa, sizeof(irq_path_isa), "%s.10", irq_path);
543                    break;
544            case MACHINE_NETWINDER:
545                    snprintf(irq_path_isa, sizeof(irq_path_isa), "%s.11", irq_path);
546                    break;
547            default:fatal("footbridge unimpl machine type\n");
548                    exit(1);
549            }
550    
551          /*  A PCI bus:  */          /*  A PCI bus:  */
552          d->pcibus = bus_pci_init(          d->pcibus = bus_pci_init(
553              devinit->machine,              devinit->machine,
554              devinit->irq_nr,    /*  PCI controller irq  */              irq_path,
555              0x7c000000,         /*  PCI device io offset  */              0x7c000000,         /*  PCI device io offset  */
556              0x80000000,         /*  PCI device mem offset  */              0x80000000,         /*  PCI device mem offset  */
557              0x00000000,         /*  PCI port base  */              0x00000000,         /*  PCI port base  */
558              0x00000000,         /*  PCI mem base  */              0x00000000,         /*  PCI mem base  */
559              0,                  /*  PCI irq base: TODO  */              irq_path,           /*  PCI irq base  */
560              0x7c000000,         /*  ISA port base  */              0x7c000000,         /*  ISA port base  */
561              0x80000000,         /*  ISA mem base  */              0x80000000,         /*  ISA mem base  */
562              32);                /*  ISA port base  */              irq_path_isa);      /*  ISA port base  */
563    
564          /*  ... with some default devices for known machine types:  */          /*  ... with some default devices for known machine types:  */
565          switch (devinit->machine->machine_type) {          switch (devinit->machine->machine_type) {
# Line 500  DEVINIT(footbridge) Line 597  DEVINIT(footbridge)
597          machine_add_tickfunction(devinit->machine,          machine_add_tickfunction(devinit->machine,
598              dev_footbridge_tick, d, DEV_FOOTBRIDGE_TICK_SHIFT, 0.0);              dev_footbridge_tick, d, DEV_FOOTBRIDGE_TICK_SHIFT, 0.0);
599    
600          devinit->return_ptr = d;          devinit->return_ptr = d->pcibus;
601          return 1;          return 1;
602  }  }
603    

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

  ViewVC Help
Powered by ViewVC 1.1.26