Revision 33f00271 hw/sd.c
b/hw/sd.c | ||
---|---|---|
96 | 96 |
qemu_irq readonly_cb; |
97 | 97 |
qemu_irq inserted_cb; |
98 | 98 |
BlockDriverState *bdrv; |
99 |
uint8_t *buf; |
|
99 | 100 |
}; |
100 | 101 |
|
101 | 102 |
static void sd_set_status(SDState *sd) |
... | ... | |
405 | 406 |
SDState *sd; |
406 | 407 |
|
407 | 408 |
sd = (SDState *) qemu_mallocz(sizeof(SDState)); |
409 |
sd->buf = qemu_memalign(512, 512); |
|
408 | 410 |
sd->spi = is_spi; |
409 | 411 |
sd_reset(sd, bs); |
410 | 412 |
bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd); |
... | ... | |
1281 | 1283 |
} |
1282 | 1284 |
|
1283 | 1285 |
/* No real need for 64 bit addresses here */ |
1284 |
static void sd_blk_read(BlockDriverState *bdrv, |
|
1285 |
void *data, uint32_t addr, uint32_t len) |
|
1286 |
static void sd_blk_read(SDState *sd, uint32_t addr, uint32_t len) |
|
1286 | 1287 |
{ |
1287 |
uint8_t buf[512]; |
|
1288 | 1288 |
uint32_t end = addr + len; |
1289 | 1289 |
|
1290 |
if (!bdrv || bdrv_read(bdrv, addr >> 9, buf, 1) == -1) {
|
|
1290 |
if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) == -1) {
|
|
1291 | 1291 |
printf("sd_blk_read: read error on host side\n"); |
1292 | 1292 |
return; |
1293 | 1293 |
} |
1294 | 1294 |
|
1295 | 1295 |
if (end > (addr & ~511) + 512) { |
1296 |
memcpy(data, buf + (addr & 511), 512 - (addr & 511));
|
|
1296 |
memcpy(sd->data, sd->buf + (addr & 511), 512 - (addr & 511));
|
|
1297 | 1297 |
|
1298 |
if (bdrv_read(bdrv, end >> 9, buf, 1) == -1) {
|
|
1298 |
if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) == -1) {
|
|
1299 | 1299 |
printf("sd_blk_read: read error on host side\n"); |
1300 | 1300 |
return; |
1301 | 1301 |
} |
1302 |
memcpy(data + 512 - (addr & 511), buf, end & 511);
|
|
1302 |
memcpy(sd->data + 512 - (addr & 511), sd->buf, end & 511);
|
|
1303 | 1303 |
} else |
1304 |
memcpy(data, buf + (addr & 511), len);
|
|
1304 |
memcpy(sd->data, sd->buf + (addr & 511), len);
|
|
1305 | 1305 |
} |
1306 | 1306 |
|
1307 |
static void sd_blk_write(BlockDriverState *bdrv, |
|
1308 |
void *data, uint32_t addr, uint32_t len) |
|
1307 |
static void sd_blk_write(SDState *sd, uint32_t addr, uint32_t len) |
|
1309 | 1308 |
{ |
1310 |
uint8_t buf[512]; |
|
1311 | 1309 |
uint32_t end = addr + len; |
1312 | 1310 |
|
1313 | 1311 |
if ((addr & 511) || len < 512) |
1314 |
if (!bdrv || bdrv_read(bdrv, addr >> 9, buf, 1) == -1) {
|
|
1312 |
if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) == -1) {
|
|
1315 | 1313 |
printf("sd_blk_write: read error on host side\n"); |
1316 | 1314 |
return; |
1317 | 1315 |
} |
1318 | 1316 |
|
1319 | 1317 |
if (end > (addr & ~511) + 512) { |
1320 |
memcpy(buf + (addr & 511), data, 512 - (addr & 511));
|
|
1321 |
if (bdrv_write(bdrv, addr >> 9, buf, 1) == -1) {
|
|
1318 |
memcpy(sd->buf + (addr & 511), sd->data, 512 - (addr & 511));
|
|
1319 |
if (bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) == -1) {
|
|
1322 | 1320 |
printf("sd_blk_write: write error on host side\n"); |
1323 | 1321 |
return; |
1324 | 1322 |
} |
1325 | 1323 |
|
1326 |
if (bdrv_read(bdrv, end >> 9, buf, 1) == -1) {
|
|
1324 |
if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) == -1) {
|
|
1327 | 1325 |
printf("sd_blk_write: read error on host side\n"); |
1328 | 1326 |
return; |
1329 | 1327 |
} |
1330 |
memcpy(buf, data + 512 - (addr & 511), end & 511);
|
|
1331 |
if (bdrv_write(bdrv, end >> 9, buf, 1) == -1)
|
|
1328 |
memcpy(sd->buf, sd->data + 512 - (addr & 511), end & 511);
|
|
1329 |
if (bdrv_write(sd->bdrv, end >> 9, sd->buf, 1) == -1)
|
|
1332 | 1330 |
printf("sd_blk_write: write error on host side\n"); |
1333 | 1331 |
} else { |
1334 |
memcpy(buf + (addr & 511), data, len);
|
|
1335 |
if (!bdrv || bdrv_write(bdrv, addr >> 9, buf, 1) == -1)
|
|
1332 |
memcpy(sd->buf + (addr & 511), sd->data, len);
|
|
1333 |
if (!sd->bdrv || bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) == -1)
|
|
1336 | 1334 |
printf("sd_blk_write: write error on host side\n"); |
1337 | 1335 |
} |
1338 | 1336 |
} |
1339 | 1337 |
|
1340 |
#define BLK_READ_BLOCK(a, len) sd_blk_read(sd->bdrv, sd->data, a, len)
|
|
1341 |
#define BLK_WRITE_BLOCK(a, len) sd_blk_write(sd->bdrv, sd->data, a, len)
|
|
1338 |
#define BLK_READ_BLOCK(a, len) sd_blk_read(sd, a, len) |
|
1339 |
#define BLK_WRITE_BLOCK(a, len) sd_blk_write(sd, a, len) |
|
1342 | 1340 |
#define APP_READ_BLOCK(a, len) memset(sd->data, 0xec, len) |
1343 | 1341 |
#define APP_WRITE_BLOCK(a, len) |
1344 | 1342 |
|
Also available in: Unified diff