summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>2019-08-18 21:16:50 +0100
committerMark Cave-Ayland <mark.cave-ayland@ilande.co.uk>2019-08-18 21:16:50 +0100
commit5a2ec0dcd0b25ac66dc8c348c27436f669f1c58c (patch)
tree47197fdf8079a74526d16de6a1a82f081b743ca1
parent4660d881aaf8ce1cd51f19f7b19c7127cbb5a3a9 (diff)
downloadqemu-openbios-5a2ec0dcd0b25ac66dc8c348c27436f669f1c58c.tar.gz
lsi: use instance value to hold sd_private_t pointer
It is also possible to remove the global_lsi variable by adding a pointer to the parent lsi_private_t instance within sd_private_t. Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
-rw-r--r--drivers/lsi.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/drivers/lsi.c b/drivers/lsi.c
index a3255479..51a541c4 100644
--- a/drivers/lsi.c
+++ b/drivers/lsi.c
@@ -18,7 +18,11 @@
#include "drivers/drivers.h"
#include "scsi.h"
-typedef struct sd_private {
+typedef struct sd_private sd_private_t;
+typedef struct lsi_table lsi_table_t;
+typedef struct lsi_private lsi_private_t;
+
+struct sd_private {
unsigned int bs;
const char *media_str[2];
uint32_t sectors;
@@ -26,9 +30,10 @@ typedef struct sd_private {
uint8_t id;
uint8_t present;
char model[40];
-} sd_private_t;
+ lsi_private_t *lsi;
+};
-typedef struct lsi_table {
+struct lsi_table {
uint32_t id;
uint32_t id_addr;
uint32_t msg_out_len;
@@ -41,9 +46,9 @@ typedef struct lsi_table {
uint32_t status_ptr;
uint32_t msg_in_len;
uint32_t msg_in_ptr;
-} lsi_table_t;
+};
-typedef struct lsi_private {
+struct lsi_private {
volatile uint8_t *mmio;
uint32_t *scripts;
uint32_t *scripts_iova;
@@ -52,9 +57,7 @@ typedef struct lsi_private {
volatile uint8_t *buffer;
volatile uint8_t *buffer_iova;
sd_private_t sd[8];
-} lsi_private_t;
-
-static lsi_private_t *global_lsi;
+};
#ifdef CONFIG_DEBUG_LSI
#define DPRINTF(fmt, args...) \
@@ -504,6 +507,7 @@ ob_sd_read_blocks(sd_private_t **sd)
ucell blk = POP();
char *dest = (char*)POP();
int pos, spb, sect_offset;
+ lsi_private_t *lsi = (*sd)->lsi;
DPRINTF("ob_sd_read_blocks id %d %lx block=%d n=%d\n", (*sd)->id, (unsigned long)dest, blk, n );
@@ -516,12 +520,12 @@ ob_sd_read_blocks(sd_private_t **sd)
sect_offset = blk / spb;
pos = (blk - sect_offset * spb) * 512;
- if (ob_sd_read_sector(global_lsi, *sd, sect_offset)) {
+ if (ob_sd_read_sector(lsi, *sd, sect_offset)) {
DPRINTF("ob_sd_read_blocks: error\n");
RET(0);
}
while (n && pos < spb * 512) {
- memcpy(dest, (uint8_t *)&global_lsi->buffer[LSI_TABLE_DATA_OFFSET] + pos, 512);
+ memcpy(dest, (uint8_t *)&lsi->buffer[LSI_TABLE_DATA_OFFSET] + pos, 512);
pos += 512;
dest += 512;
n--;
@@ -540,12 +544,12 @@ ob_sd_block_size(__attribute__((unused))sd_private_t **sd)
static void
ob_sd_open(__attribute__((unused))sd_private_t **sd)
{
- int ret = 1, id;
+ int ret = 1;
phandle_t ph;
- fword("my-unit");
- id = POP();
- *sd = &global_lsi->sd[id];
+ PUSH(find_ih_method("sd-private", my_self()));
+ fword("execute");
+ *sd = cell2pointer(POP());
#ifdef CONFIG_DEBUG_LSI
{
@@ -553,7 +557,7 @@ ob_sd_open(__attribute__((unused))sd_private_t **sd)
fword("my-args");
args = pop_fstr_copy();
- DPRINTF("opening drive %d args %s\n", id, args);
+ DPRINTF("opening drive args %s\n", args);
free(args);
}
#endif
@@ -650,8 +654,6 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram)
return -1;
}
- global_lsi = lsi;
-
/* Buffer for commands */
PUSH(0x1000);
feval("dma-alloc");
@@ -726,6 +728,9 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram)
for (id = 0; id < 8; id++) {
if (!lsi->sd[id].present)
continue;
+
+ lsi->sd[id].lsi = lsi;
+
fword("new-device");
push_str("sd");
fword("device-name");
@@ -740,6 +745,9 @@ ob_lsi_init(const char *path, uint64_t mmio, uint64_t ram)
push_str("reg");
fword("property");
+ PUSH(pointer2cell(&lsi->sd[id]));
+ feval("value sd-private");
+
BIND_NODE_METHODS(get_cur_dev(), ob_sd);
fword("finish-device");