Commit 5fedc612eb743222ee955ef21e4ff11d87a8de39

Authored by aurel32
1 parent e4d5434c

rtl8139: fix endianness on big endian targets

On big endian targets with mmio accesses, the values are not always
swapped, depending on the accessed register. The Linux 8139too module
was able to cope with that, but not the 8139cp one.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4045 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 16 additions and 26 deletions
hw/rtl8139.c
... ... @@ -2735,13 +2735,8 @@ static void rtl8139_io_writew(void *opaque, uint8_t addr, uint32_t val)
2735 2735 default:
2736 2736 DEBUG_PRINT(("RTL8139: ioport write(w) addr=0x%x val=0x%04x via write(b)\n", addr, val));
2737 2737  
2738   -#ifdef TARGET_WORDS_BIGENDIAN
2739   - rtl8139_io_writeb(opaque, addr, (val >> 8) & 0xff);
2740   - rtl8139_io_writeb(opaque, addr + 1, val & 0xff);
2741   -#else
2742 2738 rtl8139_io_writeb(opaque, addr, val & 0xff);
2743 2739 rtl8139_io_writeb(opaque, addr + 1, (val >> 8) & 0xff);
2744   -#endif
2745 2740 break;
2746 2741 }
2747 2742 }
... ... @@ -2802,17 +2797,10 @@ static void rtl8139_io_writel(void *opaque, uint8_t addr, uint32_t val)
2802 2797  
2803 2798 default:
2804 2799 DEBUG_PRINT(("RTL8139: ioport write(l) addr=0x%x val=0x%08x via write(b)\n", addr, val));
2805   -#ifdef TARGET_WORDS_BIGENDIAN
2806   - rtl8139_io_writeb(opaque, addr, (val >> 24) & 0xff);
2807   - rtl8139_io_writeb(opaque, addr + 1, (val >> 16) & 0xff);
2808   - rtl8139_io_writeb(opaque, addr + 2, (val >> 8) & 0xff);
2809   - rtl8139_io_writeb(opaque, addr + 3, val & 0xff);
2810   -#else
2811 2800 rtl8139_io_writeb(opaque, addr, val & 0xff);
2812 2801 rtl8139_io_writeb(opaque, addr + 1, (val >> 8) & 0xff);
2813 2802 rtl8139_io_writeb(opaque, addr + 2, (val >> 16) & 0xff);
2814 2803 rtl8139_io_writeb(opaque, addr + 3, (val >> 24) & 0xff);
2815   -#endif
2816 2804 break;
2817 2805 }
2818 2806 }
... ... @@ -2958,13 +2946,8 @@ static uint32_t rtl8139_io_readw(void *opaque, uint8_t addr)
2958 2946 default:
2959 2947 DEBUG_PRINT(("RTL8139: ioport read(w) addr=0x%x via read(b)\n", addr));
2960 2948  
2961   -#ifdef TARGET_WORDS_BIGENDIAN
2962   - ret = rtl8139_io_readb(opaque, addr) << 8;
2963   - ret |= rtl8139_io_readb(opaque, addr + 1);
2964   -#else
2965 2949 ret = rtl8139_io_readb(opaque, addr);
2966 2950 ret |= rtl8139_io_readb(opaque, addr + 1) << 8;
2967   -#endif
2968 2951  
2969 2952 DEBUG_PRINT(("RTL8139: ioport read(w) addr=0x%x val=0x%04x\n", addr, ret));
2970 2953 break;
... ... @@ -3031,17 +3014,10 @@ static uint32_t rtl8139_io_readl(void *opaque, uint8_t addr)
3031 3014 default:
3032 3015 DEBUG_PRINT(("RTL8139: ioport read(l) addr=0x%x via read(b)\n", addr));
3033 3016  
3034   -#ifdef TARGET_WORDS_BIGENDIAN
3035   - ret = rtl8139_io_readb(opaque, addr) << 24;
3036   - ret |= rtl8139_io_readb(opaque, addr + 1) << 16;
3037   - ret |= rtl8139_io_readb(opaque, addr + 2) << 8;
3038   - ret |= rtl8139_io_readb(opaque, addr + 3);
3039   -#else
3040 3017 ret = rtl8139_io_readb(opaque, addr);
3041 3018 ret |= rtl8139_io_readb(opaque, addr + 1) << 8;
3042 3019 ret |= rtl8139_io_readb(opaque, addr + 2) << 16;
3043 3020 ret |= rtl8139_io_readb(opaque, addr + 3) << 24;
3044   -#endif
3045 3021  
3046 3022 DEBUG_PRINT(("RTL8139: read(l) addr=0x%x val=%08x\n", addr, ret));
3047 3023 break;
... ... @@ -3091,11 +3067,17 @@ static void rtl8139_mmio_writeb(void *opaque, target_phys_addr_t addr, uint32_t
3091 3067  
3092 3068 static void rtl8139_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val)
3093 3069 {
  3070 +#ifdef TARGET_WORDS_BIGENDIAN
  3071 + val = bswap16(val);
  3072 +#endif
3094 3073 rtl8139_io_writew(opaque, addr & 0xFF, val);
3095 3074 }
3096 3075  
3097 3076 static void rtl8139_mmio_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
3098 3077 {
  3078 +#ifdef TARGET_WORDS_BIGENDIAN
  3079 + val = bswap32(val);
  3080 +#endif
3099 3081 rtl8139_io_writel(opaque, addr & 0xFF, val);
3100 3082 }
3101 3083  
... ... @@ -3106,12 +3088,20 @@ static uint32_t rtl8139_mmio_readb(void *opaque, target_phys_addr_t addr)
3106 3088  
3107 3089 static uint32_t rtl8139_mmio_readw(void *opaque, target_phys_addr_t addr)
3108 3090 {
3109   - return rtl8139_io_readw(opaque, addr & 0xFF);
  3091 + uint32_t val = rtl8139_io_readw(opaque, addr & 0xFF);
  3092 +#ifdef TARGET_WORDS_BIGENDIAN
  3093 + val = bswap16(val);
  3094 +#endif
  3095 + return val;
3110 3096 }
3111 3097  
3112 3098 static uint32_t rtl8139_mmio_readl(void *opaque, target_phys_addr_t addr)
3113 3099 {
3114   - return rtl8139_io_readl(opaque, addr & 0xFF);
  3100 + uint32_t val = rtl8139_io_readl(opaque, addr & 0xFF);
  3101 +#ifdef TARGET_WORDS_BIGENDIAN
  3102 + val = bswap32(val);
  3103 +#endif
  3104 + return val;
3115 3105 }
3116 3106  
3117 3107 /* */
... ...