qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/ide/atapi: Use the ldst API

The big-endian load/store functions are already provided
by "qemu/bswap.h".
Avoid code duplication, use the generic API.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20190808130454.9930-1-philmd@redhat.com
Signed-off-by: John Snow <jsnow@redhat.com>

authored by

Philippe Mathieu-Daudé and committed by
John Snow
614ab7d1 8ec41c42

+28 -52
+28 -52
hw/ide/atapi.c
··· 45 45 } 46 46 } 47 47 48 - static inline void cpu_to_ube16(uint8_t *buf, int val) 49 - { 50 - buf[0] = val >> 8; 51 - buf[1] = val & 0xff; 52 - } 53 - 54 - static inline void cpu_to_ube32(uint8_t *buf, unsigned int val) 55 - { 56 - buf[0] = val >> 24; 57 - buf[1] = val >> 16; 58 - buf[2] = val >> 8; 59 - buf[3] = val & 0xff; 60 - } 61 - 62 - static inline int ube16_to_cpu(const uint8_t *buf) 63 - { 64 - return (buf[0] << 8) | buf[1]; 65 - } 66 - 67 - static inline int ube32_to_cpu(const uint8_t *buf) 68 - { 69 - return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; 70 - } 71 - 72 48 static void lba_to_msf(uint8_t *buf, int lba) 73 49 { 74 50 lba += 150; ··· 485 461 uint8_t *buf_profile = buf + 12; /* start of profiles */ 486 462 487 463 buf_profile += ((*index) * 4); /* start of indexed profile */ 488 - cpu_to_ube16 (buf_profile, profile); 464 + stw_be_p(buf_profile, profile); 489 465 buf_profile[2] = ((buf_profile[0] == buf[6]) && (buf_profile[1] == buf[7])); 490 466 491 467 /* each profile adds 4 bytes to the response */ ··· 518 494 buf[7] = 0; /* default densities */ 519 495 520 496 /* FIXME: 0x30000 per spec? */ 521 - cpu_to_ube32(buf + 8, 0); /* start sector */ 522 - cpu_to_ube32(buf + 12, total_sectors - 1); /* end sector */ 523 - cpu_to_ube32(buf + 16, total_sectors - 1); /* l0 end sector */ 497 + stl_be_p(buf + 8, 0); /* start sector */ 498 + stl_be_p(buf + 12, total_sectors - 1); /* end sector */ 499 + stl_be_p(buf + 16, total_sectors - 1); /* l0 end sector */ 524 500 525 501 /* Size of buffer, not including 2 byte size field */ 526 502 stw_be_p(buf, 2048 + 2); ··· 839 815 } 840 816 841 817 /* XXX: could result in alignment problems in some architectures */ 842 - max_len = ube16_to_cpu(buf + 7); 818 + max_len = lduw_be_p(buf + 7); 843 819 844 820 /* 845 821 * XXX: avoid overflow for io_buffer if max_len is bigger than ··· 859 835 * to use as current. 0 means there is no media 860 836 */ 861 837 if (media_is_dvd(s)) { 862 - cpu_to_ube16(buf + 6, MMC_PROFILE_DVD_ROM); 838 + stw_be_p(buf + 6, MMC_PROFILE_DVD_ROM); 863 839 } else if (media_is_cd(s)) { 864 - cpu_to_ube16(buf + 6, MMC_PROFILE_CD_ROM); 840 + stw_be_p(buf + 6, MMC_PROFILE_CD_ROM); 865 841 } 866 842 867 843 buf[10] = 0x02 | 0x01; /* persistent and current */ 868 844 len = 12; /* headers: 8 + 4 */ 869 845 len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_DVD_ROM); 870 846 len += ide_atapi_set_profile(buf, &index, MMC_PROFILE_CD_ROM); 871 - cpu_to_ube32(buf, len - 4); /* data length */ 847 + stl_be_p(buf, len - 4); /* data length */ 872 848 873 849 ide_atapi_cmd_reply(s, len, max_len); 874 850 } ··· 878 854 int action, code; 879 855 int max_len; 880 856 881 - max_len = ube16_to_cpu(buf + 7); 857 + max_len = lduw_be_p(buf + 7); 882 858 action = buf[2] >> 6; 883 859 code = buf[2] & 0x3f; 884 860 ··· 886 862 case 0: /* current values */ 887 863 switch(code) { 888 864 case MODE_PAGE_R_W_ERROR: /* error recovery */ 889 - cpu_to_ube16(&buf[0], 16 - 2); 865 + stw_be_p(&buf[0], 16 - 2); 890 866 buf[2] = 0x70; 891 867 buf[3] = 0; 892 868 buf[4] = 0; ··· 905 881 ide_atapi_cmd_reply(s, 16, max_len); 906 882 break; 907 883 case MODE_PAGE_AUDIO_CTL: 908 - cpu_to_ube16(&buf[0], 24 - 2); 884 + stw_be_p(&buf[0], 24 - 2); 909 885 buf[2] = 0x70; 910 886 buf[3] = 0; 911 887 buf[4] = 0; ··· 924 900 ide_atapi_cmd_reply(s, 24, max_len); 925 901 break; 926 902 case MODE_PAGE_CAPABILITIES: 927 - cpu_to_ube16(&buf[0], 30 - 2); 903 + stw_be_p(&buf[0], 30 - 2); 928 904 buf[2] = 0x70; 929 905 buf[3] = 0; 930 906 buf[4] = 0; ··· 946 922 buf[14] |= 1 << 1; 947 923 } 948 924 buf[15] = 0x00; /* No volume & mute control, no changer */ 949 - cpu_to_ube16(&buf[16], 704); /* 4x read speed */ 925 + stw_be_p(&buf[16], 704); /* 4x read speed */ 950 926 buf[18] = 0; /* Two volume levels */ 951 927 buf[19] = 2; 952 - cpu_to_ube16(&buf[20], 512); /* 512k buffer */ 953 - cpu_to_ube16(&buf[22], 704); /* 4x read speed current */ 928 + stw_be_p(&buf[20], 512); /* 512k buffer */ 929 + stw_be_p(&buf[22], 704); /* 4x read speed current */ 954 930 buf[24] = 0; 955 931 buf[25] = 0; 956 932 buf[26] = 0; ··· 998 974 int nb_sectors, lba; 999 975 1000 976 if (buf[0] == GPCMD_READ_10) { 1001 - nb_sectors = ube16_to_cpu(buf + 7); 977 + nb_sectors = lduw_be_p(buf + 7); 1002 978 } else { 1003 - nb_sectors = ube32_to_cpu(buf + 6); 979 + nb_sectors = ldl_be_p(buf + 6); 1004 980 } 1005 981 1006 - lba = ube32_to_cpu(buf + 2); 982 + lba = ldl_be_p(buf + 2); 1007 983 if (nb_sectors == 0) { 1008 984 ide_atapi_cmd_ok(s); 1009 985 return; ··· 1017 993 int nb_sectors, lba, transfer_request; 1018 994 1019 995 nb_sectors = (buf[6] << 16) | (buf[7] << 8) | buf[8]; 1020 - lba = ube32_to_cpu(buf + 2); 996 + lba = ldl_be_p(buf + 2); 1021 997 1022 998 if (nb_sectors == 0) { 1023 999 ide_atapi_cmd_ok(s); ··· 1057 1033 unsigned int lba; 1058 1034 uint64_t total_sectors = s->nb_sectors >> 2; 1059 1035 1060 - lba = ube32_to_cpu(buf + 2); 1036 + lba = ldl_be_p(buf + 2); 1061 1037 if (lba >= total_sectors) { 1062 1038 ide_atapi_cmd_error(s, ILLEGAL_REQUEST, ASC_LOGICAL_BLOCK_OOR); 1063 1039 return; ··· 1098 1074 1099 1075 static void cmd_mechanism_status(IDEState *s, uint8_t* buf) 1100 1076 { 1101 - int max_len = ube16_to_cpu(buf + 8); 1077 + int max_len = lduw_be_p(buf + 8); 1102 1078 1103 - cpu_to_ube16(buf, 0); 1079 + stw_be_p(buf, 0); 1104 1080 /* no current LBA */ 1105 1081 buf[2] = 0; 1106 1082 buf[3] = 0; 1107 1083 buf[4] = 0; 1108 1084 buf[5] = 1; 1109 - cpu_to_ube16(buf + 6, 0); 1085 + stw_be_p(buf + 6, 0); 1110 1086 ide_atapi_cmd_reply(s, 8, max_len); 1111 1087 } 1112 1088 ··· 1116 1092 int max_len; 1117 1093 uint64_t total_sectors = s->nb_sectors >> 2; 1118 1094 1119 - max_len = ube16_to_cpu(buf + 7); 1095 + max_len = lduw_be_p(buf + 7); 1120 1096 format = buf[9] >> 6; 1121 1097 msf = (buf[1] >> 1) & 1; 1122 1098 start_track = buf[6]; ··· 1154 1130 uint64_t total_sectors = s->nb_sectors >> 2; 1155 1131 1156 1132 /* NOTE: it is really the number of sectors minus 1 */ 1157 - cpu_to_ube32(buf, total_sectors - 1); 1158 - cpu_to_ube32(buf + 4, 2048); 1133 + stl_be_p(buf, total_sectors - 1); 1134 + stl_be_p(buf + 4, 2048); 1159 1135 ide_atapi_cmd_reply(s, 8, 8); 1160 1136 } 1161 1137 1162 1138 static void cmd_read_disc_information(IDEState *s, uint8_t* buf) 1163 1139 { 1164 1140 uint8_t type = buf[1] & 7; 1165 - uint32_t max_len = ube16_to_cpu(buf + 7); 1141 + uint32_t max_len = lduw_be_p(buf + 7); 1166 1142 1167 1143 /* Types 1/2 are only defined for Blu-Ray. */ 1168 1144 if (type != 0) { ··· 1196 1172 int format = buf[7]; 1197 1173 int ret; 1198 1174 1199 - max_len = ube16_to_cpu(buf + 8); 1175 + max_len = lduw_be_p(buf + 8); 1200 1176 1201 1177 if (format < 0xff) { 1202 1178 if (media_is_cd(s)) {