Merge branch 'master' of /home/nchip/public_html/qemu into garage-push
[qemu] / hw / zaurus.c
index c475eaa..56e150d 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #include "hw.h"
 #include "pxa.h"
@@ -30,8 +29,7 @@
 
 /* SCOOP devices */
 
-struct scoop_info_s {
-    target_phys_addr_t target_base;
+struct ScoopInfo {
     qemu_irq handler[16];
     qemu_irq *in;
     uint16_t status;
@@ -46,7 +44,6 @@ struct scoop_info_s {
     uint16_t irr;
     uint16_t imr;
     uint16_t isr;
-    uint16_t gprr;
 };
 
 #define SCOOP_MCR      0x00
@@ -61,7 +58,7 @@ struct scoop_info_s {
 #define SCOOP_GPWR     0x24
 #define SCOOP_GPRR     0x28
 
-static inline void scoop_gpio_handler_update(struct scoop_info_s *s) {
+static inline void scoop_gpio_handler_update(ScoopInfo *s) {
     uint32_t level, diff;
     int bit;
     level = s->gpio_level & s->gpio_dir;
@@ -76,8 +73,7 @@ static inline void scoop_gpio_handler_update(struct scoop_info_s *s) {
 
 static uint32_t scoop_readb(void *opaque, target_phys_addr_t addr)
 {
-    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
-    addr -= s->target_base;
+    ScoopInfo *s = (ScoopInfo *) opaque;
 
     switch (addr) {
     case SCOOP_MCR:
@@ -99,9 +95,8 @@ static uint32_t scoop_readb(void *opaque, target_phys_addr_t addr)
     case SCOOP_GPCR:
         return s->gpio_dir;
     case SCOOP_GPWR:
-        return s->gpio_level;
     case SCOOP_GPRR:
-        return s->gprr;
+        return s->gpio_level;
     default:
         zaurus_printf("Bad register offset " REG_FMT "\n", addr);
     }
@@ -111,8 +106,7 @@ static uint32_t scoop_readb(void *opaque, target_phys_addr_t addr)
 
 static void scoop_writeb(void *opaque, target_phys_addr_t addr, uint32_t value)
 {
-    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
-    addr -= s->target_base;
+    ScoopInfo *s = (ScoopInfo *) opaque;
     value &= 0xffff;
 
     switch (addr) {
@@ -144,12 +138,10 @@ static void scoop_writeb(void *opaque, target_phys_addr_t addr, uint32_t value)
         scoop_gpio_handler_update(s);
         break;
     case SCOOP_GPWR:
+    case SCOOP_GPRR:   /* GPRR is probably R/O in real HW */
         s->gpio_level = value & s->gpio_dir;
         scoop_gpio_handler_update(s);
         break;
-    case SCOOP_GPRR:
-        s->gprr = value;
-        break;
     default:
         zaurus_printf("Bad register offset " REG_FMT "\n", addr);
     }
@@ -168,7 +160,7 @@ static CPUWriteMemoryFunc *scoop_writefn[] = {
 
 void scoop_gpio_set(void *opaque, int line, int level)
 {
-    struct scoop_info_s *s = (struct scoop_info_s *) s;
+    ScoopInfo *s = (ScoopInfo *) s;
 
     if (level)
         s->gpio_level |= (1 << line);
@@ -176,12 +168,12 @@ void scoop_gpio_set(void *opaque, int line, int level)
         s->gpio_level &= ~(1 << line);
 }
 
-qemu_irq *scoop_gpio_in_get(struct scoop_info_s *s)
+qemu_irq *scoop_gpio_in_get(ScoopInfo *s)
 {
     return s->in;
 }
 
-void scoop_gpio_out_set(struct scoop_info_s *s, int line,
+void scoop_gpio_out_set(ScoopInfo *s, int line,
                 qemu_irq handler) {
     if (line >= 16) {
         fprintf(stderr, "No GPIO pin %i\n", line);
@@ -193,7 +185,7 @@ void scoop_gpio_out_set(struct scoop_info_s *s, int line,
 
 static void scoop_save(QEMUFile *f, void *opaque)
 {
-    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
+    ScoopInfo *s = (ScoopInfo *) opaque;
     qemu_put_be16s(f, &s->status);
     qemu_put_be16s(f, &s->power);
     qemu_put_be32s(f, &s->gpio_level);
@@ -205,12 +197,12 @@ static void scoop_save(QEMUFile *f, void *opaque)
     qemu_put_be16s(f, &s->irr);
     qemu_put_be16s(f, &s->imr);
     qemu_put_be16s(f, &s->isr);
-    qemu_put_be16s(f, &s->gprr);
 }
 
 static int scoop_load(QEMUFile *f, void *opaque, int version_id)
 {
-    struct scoop_info_s *s = (struct scoop_info_s *) opaque;
+    uint16_t dummy;
+    ScoopInfo *s = (ScoopInfo *) opaque;
     qemu_get_be16s(f, &s->status);
     qemu_get_be16s(f, &s->power);
     qemu_get_be32s(f, &s->gpio_level);
@@ -222,28 +214,28 @@ static int scoop_load(QEMUFile *f, void *opaque, int version_id)
     qemu_get_be16s(f, &s->irr);
     qemu_get_be16s(f, &s->imr);
     qemu_get_be16s(f, &s->isr);
-    qemu_get_be16s(f, &s->gprr);
+    if (version_id < 1)
+           qemu_get_be16s(f, &dummy);
 
     return 0;
 }
 
-struct scoop_info_s *scoop_init(struct pxa2xx_state_s *cpu,
+ScoopInfo *scoop_init(PXA2xxState *cpu,
                int instance,
                target_phys_addr_t target_base) {
     int iomemtype;
-    struct scoop_info_s *s;
+    ScoopInfo *s;
 
-    s = (struct scoop_info_s *)
-            qemu_mallocz(sizeof(struct scoop_info_s));
-    memset(s, 0, sizeof(struct scoop_info_s));
+    s = (ScoopInfo *)
+            qemu_mallocz(sizeof(ScoopInfo));
+    memset(s, 0, sizeof(ScoopInfo));
 
-    s->target_base = target_base;
     s->status = 0x02;
     s->in = qemu_allocate_irqs(scoop_gpio_set, s, 16);
     iomemtype = cpu_register_io_memory(0, scoop_readfn,
                     scoop_writefn, s);
-    cpu_register_physical_memory(s->target_base, 0x1000, iomemtype);
-    register_savevm("scoop", instance, 0, scoop_save, scoop_load, s);
+    cpu_register_physical_memory(target_base, 0x1000, iomemtype);
+    register_savevm("scoop", instance, 1, scoop_save, scoop_load, s);
 
     return s;
 }
@@ -283,8 +275,8 @@ static struct __attribute__ ((__packed__)) sl_param_info {
     .phadadj           = 0x01,
 };
 
-void sl_bootparam_write(uint32_t ptr)
+void sl_bootparam_write(target_phys_addr_t ptr)
 {
-    memcpy(phys_ram_base + ptr, &zaurus_bootparam,
-                    sizeof(struct sl_param_info));
+    cpu_physical_memory_write(ptr, (void *)&zaurus_bootparam,
+                              sizeof(struct sl_param_info));
 }