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

sdhci: implement UHS-I voltage switch

[based on a patch from Alistair Francis <alistair.francis@xilinx.com>
from qemu/xilinx tag xilinx-v2015.2]
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Message-Id: <20180208164818.7961-22-f4bug@amsat.org>

authored by

Philippe Mathieu-Daudé and committed by
Paolo Bonzini
0034ebe6 238cd935

+55 -1
+13
hw/sd/core.c
··· 41 41 return SD_CARD(kid->child); 42 42 } 43 43 44 + void sdbus_set_voltage(SDBus *sdbus, uint16_t millivolts) 45 + { 46 + SDState *card = get_card(sdbus); 47 + 48 + trace_sdbus_set_voltage(sdbus_name(sdbus), millivolts); 49 + if (card) { 50 + SDCardClass *sc = SD_CARD_GET_CLASS(card); 51 + 52 + assert(sc->set_voltage); 53 + sc->set_voltage(card, millivolts); 54 + } 55 + } 56 + 44 57 int sdbus_do_command(SDBus *sdbus, SDRequest *req, uint8_t *response) 45 58 { 46 59 SDState *card = get_card(sdbus);
+13
hw/sd/sd.c
··· 128 128 bool enable; 129 129 }; 130 130 131 + static void sd_set_voltage(SDState *sd, uint16_t millivolts) 132 + { 133 + switch (millivolts) { 134 + case 3001 ... 3600: /* SD_VOLTAGE_3_3V */ 135 + case 2001 ... 3000: /* SD_VOLTAGE_3_0V */ 136 + break; 137 + default: 138 + qemu_log_mask(LOG_GUEST_ERROR, "SD card voltage not supported: %.3fV", 139 + millivolts / 1000.f); 140 + } 141 + } 142 + 131 143 static void sd_set_mode(SDState *sd) 132 144 { 133 145 switch (sd->state) { ··· 1926 1938 dc->reset = sd_reset; 1927 1939 dc->bus_type = TYPE_SD_BUS; 1928 1940 1941 + sc->set_voltage = sd_set_voltage; 1929 1942 sc->do_command = sd_do_command; 1930 1943 sc->write_data = sd_write_data; 1931 1944 sc->read_data = sd_read_data;
+11 -1
hw/sd/sdhci.c
··· 1255 1255 sdhci_update_irq(s); 1256 1256 break; 1257 1257 case SDHC_ACMD12ERRSTS: 1258 - MASKED_WRITE(s->acmd12errsts, mask, value); 1258 + MASKED_WRITE(s->acmd12errsts, mask, value & UINT16_MAX); 1259 + if (s->uhs_mode >= UHS_I) { 1260 + MASKED_WRITE(s->hostctl2, mask >> 16, value >> 16); 1261 + 1262 + if (FIELD_EX32(s->hostctl2, SDHC_HOSTCTL2, V18_ENA)) { 1263 + sdbus_set_voltage(&s->sdbus, SD_VOLTAGE_1_8V); 1264 + } else { 1265 + sdbus_set_voltage(&s->sdbus, SD_VOLTAGE_3_3V); 1266 + } 1267 + } 1259 1268 break; 1260 1269 1261 1270 case SDHC_CAPAB: ··· 1310 1319 1311 1320 #define DEFINE_SDHCI_COMMON_PROPERTIES(_state) \ 1312 1321 DEFINE_PROP_UINT8("sd-spec-version", _state, sd_spec_version, 2), \ 1322 + DEFINE_PROP_UINT8("uhs", _state, uhs_mode, UHS_NOT_SUPPORTED), \ 1313 1323 \ 1314 1324 /* Capabilities registers provide information on supported 1315 1325 * features of this specific host controller implementation */ \
+1
hw/sd/trace-events
··· 4 4 sdbus_command(const char *bus_name, uint8_t cmd, uint32_t arg, uint8_t crc) "@%s CMD%02d arg 0x%08x crc 0x%02x" 5 5 sdbus_read(const char *bus_name, uint8_t value) "@%s value 0x%02x" 6 6 sdbus_write(const char *bus_name, uint8_t value) "@%s value 0x%02x" 7 + sdbus_set_voltage(const char *bus_name, uint16_t millivolts) "@%s %u (mV)" 7 8 8 9 # hw/sd/sdhci.c 9 10 sdhci_set_inserted(const char *level) "card state changed: %s"
+16
include/hw/sd/sd.h
··· 56 56 #define OCR_CCS_BITN 30 57 57 58 58 typedef enum { 59 + SD_VOLTAGE_0_4V = 400, /* currently not supported */ 60 + SD_VOLTAGE_1_8V = 1800, 61 + SD_VOLTAGE_3_0V = 3000, 62 + SD_VOLTAGE_3_3V = 3300, 63 + } sd_voltage_mv_t; 64 + 65 + typedef enum { 66 + UHS_NOT_SUPPORTED = 0, 67 + UHS_I = 1, 68 + UHS_II = 2, /* currently not supported */ 69 + UHS_III = 3, /* currently not supported */ 70 + } sd_uhs_mode_t; 71 + 72 + typedef enum { 59 73 sd_none = -1, 60 74 sd_bc = 0, /* broadcast -- no response */ 61 75 sd_bcr, /* broadcast with response */ ··· 88 102 void (*write_data)(SDState *sd, uint8_t value); 89 103 uint8_t (*read_data)(SDState *sd); 90 104 bool (*data_ready)(SDState *sd); 105 + void (*set_voltage)(SDState *sd, uint16_t millivolts); 91 106 void (*enable)(SDState *sd, bool enable); 92 107 bool (*get_inserted)(SDState *sd); 93 108 bool (*get_readonly)(SDState *sd); ··· 134 149 /* Functions to be used by qdevified callers (working via 135 150 * an SDBus rather than directly with SDState) 136 151 */ 152 + void sdbus_set_voltage(SDBus *sdbus, uint16_t millivolts); 137 153 int sdbus_do_command(SDBus *sd, SDRequest *req, uint8_t *response); 138 154 void sdbus_write_data(SDBus *sd, uint8_t value); 139 155 uint8_t sdbus_read_data(SDBus *sd);
+1
include/hw/sd/sdhci.h
··· 96 96 bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ 97 97 uint32_t quirks; 98 98 uint8_t sd_spec_version; 99 + uint8_t uhs_mode; 99 100 } SDHCIState; 100 101 101 102 /*