microblaze: linux-user support.
[qemu] / hw / sd.c
diff --git a/hw/sd.c b/hw/sd.c
index 4618883..9888547 100644 (file)
--- a/hw/sd.c
+++ b/hw/sd.c
 //#define DEBUG_SD 1
 
 #ifdef DEBUG_SD
-#define DPRINTF(fmt, args...) \
-do { fprintf(stderr, "SD: " fmt , ##args); } while (0)
+#define DPRINTF(fmt, ...) \
+do { fprintf(stderr, "SD: " fmt , ## __VA_ARGS__); } while (0)
 #else
-#define DPRINTF(fmt, args...) do {} while(0)
+#define DPRINTF(fmt, ...) do {} while(0)
 #endif
 
 typedef enum {
@@ -301,7 +301,7 @@ static void sd_set_sdstatus(SDState *sd)
     memset(sd->sd_status, 0, 64);
 }
 
-static int sd_req_crc_validate(struct sd_request_s *req)
+static int sd_req_crc_validate(SDRequest *req)
 {
     uint8_t buffer[5];
     buffer[0] = 0x40 | req->cmd;
@@ -365,7 +365,11 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
     uint32_t size;
     uint64_t sect;
 
-    bdrv_get_geometry(bdrv, &sect);
+    if (bdrv) {
+        bdrv_get_geometry(bdrv, &sect);
+    } else {
+        sect = 0;
+    }
     sect <<= 9;
 
     if (sect > 0x40000000)
@@ -388,7 +392,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
 
     if (sd->wp_groups)
         qemu_free(sd->wp_groups);
-    sd->wp_switch = bdrv_is_read_only(bdrv);
+    sd->wp_switch = bdrv ? bdrv_is_read_only(bdrv) : 0;
     sd->wp_groups = (int *) qemu_mallocz(sizeof(int) * sect);
     memset(sd->function_group, 0, sizeof(int) * 6);
     sd->erase_start = 0;
@@ -421,7 +425,9 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)
     sd->spi = is_spi;
     sd->enable = 1;
     sd_reset(sd, bs);
-    bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
+    if (sd->bdrv) {
+        bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
+    }
     return sd;
 }
 
@@ -574,7 +580,7 @@ static void sd_lock_command(SDState *sd)
 }
 
 static sd_rsp_type_t sd_normal_command(SDState *sd,
-                                       struct sd_request_s req)
+                                       SDRequest req)
 {
     uint32_t rca = 0x0000;
 
@@ -1113,7 +1119,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
 }
 
 static sd_rsp_type_t sd_app_command(SDState *sd,
-                                    struct sd_request_s req) {
+                                    SDRequest req) {
     uint32_t rca;
 
     if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc)
@@ -1222,13 +1228,13 @@ static sd_rsp_type_t sd_app_command(SDState *sd,
     return sd_r0;
 }
 
-int sd_do_command(SDState *sd, struct sd_request_s *req,
+int sd_do_command(SDState *sd, SDRequest *req,
                   uint8_t *response) {
     uint32_t last_status = sd->card_status;
     sd_rsp_type_t rtype;
     int rsplen;
 
-    if (!bdrv_is_inserted(sd->bdrv) || !sd->enable) {
+    if (!sd->bdrv || !bdrv_is_inserted(sd->bdrv) || !sd->enable) {
         return 0;
     }