Diff for /qemu/hw/jazz_led.c between versions 1.1 and 1.1.1.7

version 1.1, 2018/04/24 16:48:23 version 1.1.1.7, 2018/04/24 19:46:42
Line 1 Line 1
 /*  /*
  * QEMU JAZZ LED emulator.   * QEMU JAZZ LED emulator.
  *   *
  * Copyright (c) 2007 Hervé Poussineau   * Copyright (c) 2007-2012 Herve Poussineau
  *   *
  * Permission is hereby granted, free of charge, to any person obtaining a copy   * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal   * of this software and associated documentation files (the "Software"), to deal
Line 22 Line 22
  * THE SOFTWARE.   * THE SOFTWARE.
  */   */
   
 #include "hw.h"  
 #include "mips.h"  
 #include "console.h"  #include "console.h"
 #include "pixel_ops.h"  #include "pixel_ops.h"
   #include "trace.h"
 //#define DEBUG_LED  #include "sysbus.h"
   
 typedef enum {  typedef enum {
     REDRAW_NONE = 0, REDRAW_SEGMENTS = 1, REDRAW_BACKGROUND = 2,      REDRAW_NONE = 0, REDRAW_SEGMENTS = 1, REDRAW_BACKGROUND = 2,
 } screen_state_t;  } screen_state_t;
   
 typedef struct LedState {  typedef struct LedState {
     target_phys_addr_t base;      SysBusDevice busdev;
       MemoryRegion iomem;
     uint8_t segments;      uint8_t segments;
     DisplayState *ds;      DisplayState *ds;
     screen_state_t state;      screen_state_t state;
 } LedState;  } LedState;
   
 static uint32_t led_readb(void *opaque, target_phys_addr_t addr)  static uint64_t jazz_led_read(void *opaque, target_phys_addr_t addr,
                                 unsigned int size)
 {  {
     LedState *s = opaque;      LedState *s = opaque;
     int relative_addr = addr - s->base;      uint8_t val;
     uint32_t val;  
   
     switch (relative_addr) {      val = s->segments;
         case 0:      trace_jazz_led_read(addr, val);
             val = s->segments;  
             break;  
         default:  
 #ifdef DEBUG_LED  
             printf("jazz led: invalid read [0x%x]\n", relative_addr);  
 #endif  
             val = 0;  
     }  
   
     return val;      return val;
 }  }
   
 static uint32_t led_readw(void *opaque, target_phys_addr_t addr)  static void jazz_led_write(void *opaque, target_phys_addr_t addr,
 {                             uint64_t val, unsigned int size)
     uint32_t v;  
 #ifdef TARGET_WORDS_BIGENDIAN  
     v = led_readb(opaque, addr) << 8;  
     v |= led_readb(opaque, addr + 1);  
 #else  
     v = led_readb(opaque, addr);  
     v |= led_readb(opaque, addr + 1) << 8;  
 #endif  
     return v;  
 }  
   
 static uint32_t led_readl(void *opaque, target_phys_addr_t addr)  
 {  
     uint32_t v;  
 #ifdef TARGET_WORDS_BIGENDIAN  
     v = led_readb(opaque, addr) << 24;  
     v |= led_readb(opaque, addr + 1) << 16;  
     v |= led_readb(opaque, addr + 2) << 8;  
     v |= led_readb(opaque, addr + 3);  
 #else  
     v = led_readb(opaque, addr);  
     v |= led_readb(opaque, addr + 1) << 8;  
     v |= led_readb(opaque, addr + 2) << 16;  
     v |= led_readb(opaque, addr + 3) << 24;  
 #endif  
     return v;  
 }  
   
 static void led_writeb(void *opaque, target_phys_addr_t addr, uint32_t val)  
 {  {
     LedState *s = opaque;      LedState *s = opaque;
     int relative_addr = addr - s->base;      uint8_t new_val = val & 0xff;
   
     switch (relative_addr) {      trace_jazz_led_write(addr, new_val);
         case 0:  
             s->segments = val;  
             s->state |= REDRAW_SEGMENTS;  
             break;  
         default:  
 #ifdef DEBUG_LED  
             printf("jazz led: invalid write of 0x%02x at [0x%x]\n", val, relative_addr);  
 #endif  
             break;  
     }  
 }  
   
 static void led_writew(void *opaque, target_phys_addr_t addr, uint32_t val)      s->segments = new_val;
 {      s->state |= REDRAW_SEGMENTS;
 #ifdef TARGET_WORDS_BIGENDIAN  }
     led_writeb(opaque, addr, (val >> 8) & 0xff);  
     led_writeb(opaque, addr + 1, val & 0xff);  
 #else  
     led_writeb(opaque, addr, val & 0xff);  
     led_writeb(opaque, addr + 1, (val >> 8) & 0xff);  
 #endif  
 }  
   
 static void led_writel(void *opaque, target_phys_addr_t addr, uint32_t val)  
 {  
 #ifdef TARGET_WORDS_BIGENDIAN  
     led_writeb(opaque, addr, (val >> 24) & 0xff);  
     led_writeb(opaque, addr + 1, (val >> 16) & 0xff);  
     led_writeb(opaque, addr + 2, (val >> 8) & 0xff);  
     led_writeb(opaque, addr + 3, val & 0xff);  
 #else  
     led_writeb(opaque, addr, val & 0xff);  
     led_writeb(opaque, addr + 1, (val >> 8) & 0xff);  
     led_writeb(opaque, addr + 2, (val >> 16) & 0xff);  
     led_writeb(opaque, addr + 3, (val >> 24) & 0xff);  
 #endif  
 }  
   
 static CPUReadMemoryFunc *led_read[3] = {  
     led_readb,  
     led_readw,  
     led_readl,  
 };  
   
 static CPUWriteMemoryFunc *led_write[3] = {  static const MemoryRegionOps led_ops = {
     led_writeb,      .read = jazz_led_read,
     led_writew,      .write = jazz_led_write,
     led_writel,      .endianness = DEVICE_NATIVE_ENDIAN,
       .impl.min_access_size = 1,
       .impl.max_access_size = 1,
 };  };
   
 /***********************************************************/  /***********************************************************/
Line 154  static void draw_horizontal_line(Display Line 79  static void draw_horizontal_line(Display
     uint8_t *d;      uint8_t *d;
     int x, bpp;      int x, bpp;
   
     bpp = (ds->depth + 7) >> 3;      bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
     d = ds->data + ds->linesize * posy + bpp * posx1;      d = ds_get_data(ds) + ds_get_linesize(ds) * posy + bpp * posx1;
     switch(bpp) {      switch(bpp) {
         case 1:          case 1:
             for (x = posx1; x <= posx2; x++) {              for (x = posx1; x <= posx2; x++) {
Line 183  static void draw_vertical_line(DisplaySt Line 108  static void draw_vertical_line(DisplaySt
     uint8_t *d;      uint8_t *d;
     int y, bpp;      int y, bpp;
   
     bpp = (ds->depth + 7) >> 3;      bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
     d = ds->data + ds->linesize * posy1 + bpp * posx;      d = ds_get_data(ds) + ds_get_linesize(ds) * posy1 + bpp * posx;
     switch(bpp) {      switch(bpp) {
         case 1:          case 1:
             for (y = posy1; y <= posy2; y++) {              for (y = posy1; y <= posy2; y++) {
                 *((uint8_t *)d) = color;                  *((uint8_t *)d) = color;
                 d += ds->linesize;                  d += ds_get_linesize(ds);
             }              }
             break;              break;
         case 2:          case 2:
             for (y = posy1; y <= posy2; y++) {              for (y = posy1; y <= posy2; y++) {
                 *((uint16_t *)d) = color;                  *((uint16_t *)d) = color;
                 d += ds->linesize;                  d += ds_get_linesize(ds);
             }              }
             break;              break;
         case 4:          case 4:
             for (y = posy1; y <= posy2; y++) {              for (y = posy1; y <= posy2; y++) {
                 *((uint32_t *)d) = color;                  *((uint32_t *)d) = color;
                 d += ds->linesize;                  d += ds_get_linesize(ds);
             }              }
             break;              break;
     }      }
Line 217  static void jazz_led_update_display(void Line 142  static void jazz_led_update_display(void
   
     if (s->state & REDRAW_BACKGROUND) {      if (s->state & REDRAW_BACKGROUND) {
         /* clear screen */          /* clear screen */
         bpp = (ds->depth + 7) >> 3;          bpp = (ds_get_bits_per_pixel(ds) + 7) >> 3;
         d1 = ds->data;          d1 = ds_get_data(ds);
         for (y = 0; y < ds->height; y++) {          for (y = 0; y < ds_get_height(ds); y++) {
             memset(d1, 0x00, ds->width * bpp);              memset(d1, 0x00, ds_get_width(ds) * bpp);
             d1 += ds->linesize;              d1 += ds_get_linesize(ds);
         }          }
     }      }
   
     if (s->state & REDRAW_SEGMENTS) {      if (s->state & REDRAW_SEGMENTS) {
         /* set colors according to bpp */          /* set colors according to bpp */
         switch (ds->depth) {          switch (ds_get_bits_per_pixel(ds)) {
             case 8:              case 8:
                 color_segment = rgb_to_pixel8(0xaa, 0xaa, 0xaa);                  color_segment = rgb_to_pixel8(0xaa, 0xaa, 0xaa);
                 color_led = rgb_to_pixel8(0x00, 0xff, 0x00);                  color_led = rgb_to_pixel8(0x00, 0xff, 0x00);
Line 271  static void jazz_led_update_display(void Line 196  static void jazz_led_update_display(void
     }      }
   
     s->state = REDRAW_NONE;      s->state = REDRAW_NONE;
     dpy_update(ds, 0, 0, ds->width, ds->height);      dpy_update(ds, 0, 0, ds_get_width(ds), ds_get_height(ds));
 }  }
   
 static void jazz_led_invalidate_display(void *opaque)  static void jazz_led_invalidate_display(void *opaque)
Line 280  static void jazz_led_invalidate_display( Line 205  static void jazz_led_invalidate_display(
     s->state |= REDRAW_SEGMENTS | REDRAW_BACKGROUND;      s->state |= REDRAW_SEGMENTS | REDRAW_BACKGROUND;
 }  }
   
 static void jazz_led_screen_dump(void *opaque, const char *filename)  static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
 {  {
     printf("jazz_led_screen_dump() not implemented\n");      LedState *s = opaque;
       char buf[2];
   
       dpy_cursor(s->ds, -1, -1);
       qemu_console_resize(s->ds, 2, 1);
   
       /* TODO: draw the segments */
       snprintf(buf, 2, "%02hhx\n", s->segments);
       console_write_ch(chardata++, 0x00200100 | buf[0]);
       console_write_ch(chardata++, 0x00200100 | buf[1]);
   
       dpy_update(s->ds, 0, 0, 2, 1);
 }  }
   
 void jazz_led_init(DisplayState *ds, target_phys_addr_t base)  static int jazz_led_post_load(void *opaque, int version_id)
 {  {
     LedState *s;      /* force refresh */
     int io;      jazz_led_invalidate_display(opaque);
   
     s = qemu_mallocz(sizeof(LedState));      return 0;
     if (!s)  }
         return;  
   
     s->base = base;  static const VMStateDescription vmstate_jazz_led = {
     s->ds = ds;      .name = "jazz-led",
       .version_id = 0,
       .minimum_version_id = 0,
       .minimum_version_id_old = 0,
       .post_load = jazz_led_post_load,
       .fields = (VMStateField[]) {
           VMSTATE_UINT8(segments, LedState),
           VMSTATE_END_OF_LIST()
       }
   };
   
   static int jazz_led_init(SysBusDevice *dev)
   {
       LedState *s = FROM_SYSBUS(LedState, dev);
   
       memory_region_init_io(&s->iomem, &led_ops, s, "led", 1);
       sysbus_init_mmio(dev, &s->iomem);
   
       s->ds = graphic_console_init(jazz_led_update_display,
                                    jazz_led_invalidate_display,
                                    NULL,
                                    jazz_led_text_update, s);
   
       return 0;
   }
   
   static void jazz_led_reset(DeviceState *d)
   {
       LedState *s = DO_UPCAST(LedState, busdev.qdev, d);
   
       s->segments = 0;
     s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;      s->state = REDRAW_SEGMENTS | REDRAW_BACKGROUND;
       qemu_console_resize(s->ds, 60, 80);
   }
   
     io = cpu_register_io_memory(0, led_read, led_write, s);  static void jazz_led_class_init(ObjectClass *klass, void *data)
     cpu_register_physical_memory(s->base, 1, io);  {
       DeviceClass *dc = DEVICE_CLASS(klass);
       SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
   
     graphic_console_init(ds, jazz_led_update_display, jazz_led_invalidate_display, jazz_led_screen_dump, s);      k->init = jazz_led_init;
       dc->desc = "Jazz LED display",
       dc->vmsd = &vmstate_jazz_led;
       dc->reset = jazz_led_reset;
 }  }
   
   static TypeInfo jazz_led_info = {
       .name          = "jazz-led",
       .parent        = TYPE_SYS_BUS_DEVICE,
       .instance_size = sizeof(LedState),
       .class_init    = jazz_led_class_init,
   };
   
   static void jazz_led_register(void)
   {
       type_register_static(&jazz_led_info);
   }
   
   type_init(jazz_led_register);

Removed from v.1.1  
changed lines
  Added in v.1.1.1.7


unix.superglobalmegacorp.com