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

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

revision 12 by dpavlin, Mon Oct 8 16:18:38 2007 UTC revision 34 by dpavlin, Mon Oct 8 16:21:17 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  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_asc.c,v 1.74 2005/07/27 06:57:34 debug Exp $   *  $Id: dev_asc.c,v 1.84 2006/12/31 21:35:26 debug Exp $
29   *   *
30   *  'asc' SCSI controller for some DECstation/DECsystem models, and   *  'asc' SCSI controller for some DECstation/DECsystem models and PICA-61.
  *  for PICA-61.  
31   *   *
32   *  Supposed to support SCSI-1 and SCSI-2. I've not yet found any docs   *  Supposed to support SCSI-1 and SCSI-2. I've not yet found any docs
33   *  on NCR53C9X, so I'll try to implement this device from LSI53CF92A docs   *  on NCR53C9X, so I'll try to implement this device from LSI53CF92A docs
# Line 50  Line 49 
49   *  TODO:  This module needs a clean-up, and some testing to see that   *  TODO:  This module needs a clean-up, and some testing to see that
50   *         it works will all OSes that might use it (NetBSD, OpenBSD,   *         it works will all OSes that might use it (NetBSD, OpenBSD,
51   *         Ultrix, Linux, Mach, OSF/1, Sprite, ...)   *         Ultrix, Linux, Mach, OSF/1, Sprite, ...)
52     *
53     *         Running Linux/DECstation 2.4.26 with no scsi disks attached causes
54     *         a warning message to be printed by Linux. (Whether this is a bug,
55     *         is is the way it works on real hardware, I don't know.)
56   */   */
57    
58  #include <stdio.h>  #include <stdio.h>
# Line 98  struct asc_data { Line 101  struct asc_data {
101          int             mode;          int             mode;
102    
103          void            *turbochannel;          void            *turbochannel;
104          int             irq_nr;          struct interrupt irq;
105          int             irq_caused_last_time;          int             irq_asserted;
106    
107          /*  Current state and transfer:  */          /*  Current state and transfer:  */
108          int             cur_state;          int             cur_state;
# Line 149  static int dev_asc_select(struct cpu *cp Line 152  static int dev_asc_select(struct cpu *cp
152          int to_id, int dmaflag, int n_messagebytes);          int to_id, int dmaflag, int n_messagebytes);
153    
154    
155  /*  DEVICE_TICK(asc)
  *  dev_asc_tick():  
  *  
  *  This function is called "every now and then" from the CPU  
  *  main loop.  
  */  
 void dev_asc_tick(struct cpu *cpu, void *extra)  
156  {  {
157          struct asc_data *d = extra;          struct asc_data *d = extra;
158            int new_assert = d->reg_ro[NCR_STAT] & NCRSTAT_INT;
159    
160          if (d->reg_ro[NCR_STAT] & NCRSTAT_INT)          if (new_assert && !d->irq_asserted)
161                  cpu_interrupt(cpu, d->irq_nr);                  INTERRUPT_ASSERT(d->irq);
162    
163            d->irq_asserted = new_assert;
164  }  }
165    
166    
# Line 309  fatal("TODO..............\n"); Line 309  fatal("TODO..............\n");
309                                  fatal("no incoming DMA data?\n");                                  fatal("no incoming DMA data?\n");
310                                  res = 0;                                  res = 0;
311                          } else {                          } else {
312                                  int len = d->xferp->data_in_len;                                  size_t len = d->xferp->data_in_len;
313                                  int len2 = d->reg_wo[NCR_TCL] +                                  size_t len2 = d->reg_wo[NCR_TCL] +
314                                      d->reg_wo[NCR_TCM] * 256;                                      d->reg_wo[NCR_TCM] * 256;
315                                  if (len2 == 0)                                  if (len2 == 0)
316                                          len2 = 65536;                                          len2 = 65536;
# Line 748  static int dev_asc_select(struct cpu *cp Line 748  static int dev_asc_select(struct cpu *cp
748  }  }
749    
750    
751  /*  DEVICE_ACCESS(asc_address_reg)
  *  dev_asc_address_reg_access():  
  */  
 int dev_asc_address_reg_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
752  {  {
753          struct asc_data *d = extra;          struct asc_data *d = extra;
754    
# Line 770  int dev_asc_address_reg_access(struct cp Line 765  int dev_asc_address_reg_access(struct cp
765  }  }
766    
767    
768  /*  DEVICE_ACCESS(asc_dma)
  *  dev_asc_dma_access():  
  */  
 int dev_asc_dma_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
769  {  {
770          struct asc_data *d = extra;          struct asc_data *d = extra;
771    
# Line 813  int dev_asc_dma_access(struct cpu *cpu, Line 803  int dev_asc_dma_access(struct cpu *cpu,
803  }  }
804    
805    
806  /*  DEVICE_ACCESS(asc)
  *  dev_asc_access():  
  */  
 int dev_asc_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
807  {  {
808          int regnr;          int regnr;
809          struct asc_data *d = extra;          struct asc_data *d = extra;
# Line 826  int dev_asc_access(struct cpu *cpu, stru Line 811  int dev_asc_access(struct cpu *cpu, stru
811          int n_messagebytes = 0;          int n_messagebytes = 0;
812          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
813    
814            if (writeflag == MEM_WRITE)
815          idata = memory_readmax64(cpu, data, len);                  idata = memory_readmax64(cpu, data, len);
816    
817  #if 0  #if 0
818          /*  Debug stuff useful when trying to make dev_asc compatible          /*  Debug stuff useful when trying to make dev_asc compatible
# Line 1214  break; Line 1199  break;
1199                          d->reg_ro[NCR_STAT] = PHASE_COMMAND;                          d->reg_ro[NCR_STAT] = PHASE_COMMAND;
1200                  }                  }
1201    
1202                  cpu_interrupt_ack(cpu, d->irq_nr);                  INTERRUPT_DEASSERT(d->irq);
1203                    d->irq_asserted = 0;
1204          }          }
1205    
1206          if (regnr == NCR_CFG1) {          if (regnr == NCR_CFG1) {
# Line 1244  break; Line 1230  break;
1230   *  Register an 'asc' device.   *  Register an 'asc' device.
1231   */   */
1232  void dev_asc_init(struct machine *machine, struct memory *mem,  void dev_asc_init(struct machine *machine, struct memory *mem,
1233          uint64_t baseaddr, int irq_nr, void *turbochannel,          uint64_t baseaddr, char *irq_path, void *turbochannel, int mode,
         int mode,  
1234          size_t (*dma_controller)(void *dma_controller_data,          size_t (*dma_controller)(void *dma_controller_data,
1235                  unsigned char *data, size_t len, int writeflag),                  unsigned char *data, size_t len, int writeflag),
1236          void *dma_controller_data)          void *dma_controller_data)
# Line 1258  void dev_asc_init(struct machine *machin Line 1243  void dev_asc_init(struct machine *machin
1243                  exit(1);                  exit(1);
1244          }          }
1245          memset(d, 0, sizeof(struct asc_data));          memset(d, 0, sizeof(struct asc_data));
1246          d->irq_nr       = irq_nr;  
1247            INTERRUPT_CONNECT(irq_path, d->irq);
1248          d->turbochannel = turbochannel;          d->turbochannel = turbochannel;
1249          d->mode         = mode;          d->mode         = mode;
1250    
# Line 1277  void dev_asc_init(struct machine *machin Line 1263  void dev_asc_init(struct machine *machin
1263          d->dma_controller_data = dma_controller_data;          d->dma_controller_data = dma_controller_data;
1264    
1265          memory_device_register(mem, "asc", baseaddr,          memory_device_register(mem, "asc", baseaddr,
1266              mode == DEV_ASC_PICA?              mode == DEV_ASC_PICA? DEV_ASC_PICA_LENGTH : DEV_ASC_DEC_LENGTH,
1267                  DEV_ASC_PICA_LENGTH : DEV_ASC_DEC_LENGTH,              dev_asc_access, d, DM_DEFAULT, NULL);
             dev_asc_access, d, MEM_DEFAULT, NULL);  
1268    
1269          if (mode == DEV_ASC_DEC) {          if (mode == DEV_ASC_DEC) {
1270                  memory_device_register(mem, "asc_dma_address_reg",                  memory_device_register(mem, "asc_dma_address_reg",
1271                      baseaddr + 0x40000, 4096, dev_asc_address_reg_access, d,                      baseaddr + 0x40000, 4096, dev_asc_address_reg_access, d,
1272                      MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK,                      DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK,
1273                      (unsigned char *)&d->dma_address_reg_memory[0]);                      (unsigned char *)&d->dma_address_reg_memory[0]);
1274                  memory_device_register(mem, "asc_dma", baseaddr + 0x80000,                  memory_device_register(mem, "asc_dma", baseaddr + 0x80000,
1275                      ASC_DMA_SIZE, dev_asc_dma_access, d,                      ASC_DMA_SIZE, dev_asc_dma_access, d,
1276                      MEM_DYNTRANS_OK | MEM_DYNTRANS_WRITE_OK, d->dma);                      DM_DYNTRANS_OK | DM_DYNTRANS_WRITE_OK, d->dma);
1277          }          }
1278    
1279          machine_add_tickfunction(machine, dev_asc_tick, d, ASC_TICK_SHIFT);          machine_add_tickfunction(machine, dev_asc_tick, d, ASC_TICK_SHIFT, 0.0);
1280  }  }
1281    

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

  ViewVC Help
Powered by ViewVC 1.1.26