symbian-qemu-0.9.1-12/qemu-symbian-svp/plugins/syborg_nvmemorydevice.py
author andrewj
Fri, 15 Oct 2010 16:19:01 +0100
changeset 121 f4712cc7c69e
parent 93 07b904f40417
permissions -rw-r--r--
NTT DOCOMO, INC - Fix for Bug 2917 - svphostfs filesystem doesn't return UID details for RFs:Entry
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     1
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     2
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     3
# All rights reserved.
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     4
# This component and the accompanying materials are made available
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     6
# which accompanies this distribution, and is available
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     8
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
     9
# Initial Contributors:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    11
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    12
# Contributors:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    13
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    14
# Description: syborg_nvmemorydevice.py
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    15
# A simple non volatile memory device nvmemory.dll python wrapper
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    16
# Represents a non volatile memory device register interface for quest OS in QEMU Syborg environment.
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    17
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    18
# Gets the following from devicetree (.dtb configuration file) 
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    19
#       drive_size - the size of the non volatile memory array to be created if there is no such thing available when the system is started
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    20
#       sector_size - the size of the sector for the memory device
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    21
#       drive_image_name - the name of the image to be used
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    22
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    23
# Creates an empty image of specified size and name if there is not image available when the system is started
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    24
#
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    25
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    26
import ctypes
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    27
import qemu
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    28
import sys
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    29
import os
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    30
import array
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    31
import platform
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    32
import re
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    33
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    34
class syborg_nvmemorydevice(qemu.devclass):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    35
    # 256 MB default empty drive size if there is no readymade image available
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    36
    DEFAULT_DRIVE_SIZE = 0x10000000
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    37
    DEVICE_SECTOR_SIZE = 0x200
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    38
    DRIVE_NAME = "qemudrive.img"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    39
    DRIVE_PATH = "nvmemory"
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    40
    
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    41
    # Memory device registers
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    42
    R_NVMEM_ID                                = 0x0000
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    43
    R_NVMEM_TRANSACTION_OFFSET                = 0x0004
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    44
    R_NVMEM_TRANSACTION_SIZE                  = 0x0008
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    45
    R_NVMEM_TRANSACTION_DIRECTION             = 0x000c
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    46
    R_NVMEM_TRANSACTION_EXECUTE               = 0x0010
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    47
    R_NVMEM_SHARED_MEMORY_BASE                = 0x0014
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    48
    R_NVMEM_NV_MEMORY_SIZE                    = 0x0018
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    49
    R_NVMEM_SHARED_MEMORY_SIZE                = 0x001c
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    50
    R_NVMEM_STATUS                            = 0x0020
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    51
    R_NVMEM_ENABLE                            = 0x0024
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    52
    R_NVMEM_LASTREG                           = 0x0028  # not a register, address of last register
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    53
    
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    54
    NVMEM_TRANSACTION_READ              = 1
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    55
    NVMEM_TRANSACTION_WRITE             = 2
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    56
    # Variables to store the information for current transaction
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    57
    shared_memory_base                  = 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    58
    shared_memory_size                  = 0
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    59
    transaction_offset                  = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    60
    transaction_size                    = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    61
    transaction_direction               = 0
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    62
    # Variables to validate transaction
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    63
    transaction_offset_set              = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    64
    transaction_size_set                = 0
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    65
    transaction_direction_set           = 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    66
    nvmemory_sector_count                = 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    67
    
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    68
    drive_size                          = 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    69
    sector_size                         = 0
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    70
    drive_image_name                    = ""
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    71
    host_plat = platform.platform();
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    72
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    73
    def create(self):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    74
        print "syborg_nvmemorydevice: create\n"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    75
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    76
        # Get properties
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    77
        self.drive_size = self.properties["drive_size"]
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    78
        self.sector_size = self.properties["sector_size"]
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    79
        self.drive_image_name = self.properties["drive_image_name"]
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    80
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    81
        print "drive size: ", self.drive_size
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    82
        print "sector size: ", self.sector_size
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    83
        print "drive name: ", self.drive_image_name
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    84
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    85
        drive_path_and_name = os.path.join(self.DRIVE_PATH, self.drive_image_name)  
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    86
        # Save working directory
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    87
        self.working_dir = os.getcwd()
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    88
        nvmem_lib = ""
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    89
        open_mode = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    90
        if re.match('^linux',self.host_plat,re.I):
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    91
			nvmemlib_name = "libnvmemmory.so"
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    92
			open_mode = os.O_RDWR
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    93
        else:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    94
			nvmemlib_name = "nvmemmory.dll"
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    95
			open_mode = os.O_RDWR|os.O_BINARY			
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    96
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    97
        # Open the nvmemory library
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
    98
        try:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
    99
            self.nvmemlib = ctypes.CDLL(nvmemlib_name)
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   100
        except Exception, e:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   101
            print repr(e)
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   102
            sys.exit("syborg_nvmemorydevice: nvmemmory load failed")
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   103
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   104
        # Create an instance of non volatile memory handler class
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   105
        self.obj = self.nvmemlib.nvmem_create( self.sector_size )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   106
        self.nvmemlib.nvmem_reset( self.obj )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   107
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   108
        # Create drive image path
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   109
        try:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   110
            print "syborg_nvmemorydevice: Check drive image path\n"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   111
            os.mkdir( self.DRIVE_PATH )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   112
        except:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   113
            # Here we could check why we failed - usually because the path already exists \n"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   114
            pass
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   115
        try:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   116
            self.filehandle = os.open( drive_path_and_name, open_mode )
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   117
            os.close( self.filehandle )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   118
        except:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   119
            print "syborg_nvmemorydevice: drive image not found - create\n"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   120
            self.filehandle = open( drive_path_and_name, "wb" )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   121
            # Initialize file with zeroes. This may take a while
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   122
            temparray = array.array("B", [0,0,0,0,0,0,0,0])
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   123
            arraylength = temparray.buffer_info()[1] * temparray.itemsize
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   124
            multiplier = self.drive_size / arraylength / 128
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   125
            temparray = temparray * multiplier
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   126
            arraylength = temparray.buffer_info()[1] * temparray.itemsize
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   127
            print "array length: ", arraylength
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   128
            index = 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   129
            while index < 128:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   130
                temparray.tofile(self.filehandle)
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   131
                index = index+1
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   132
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   133
        # Create path and get handle to the raw memory array
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   134
        imagepath = os.path.join(self.working_dir, drive_path_and_name)
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   135
        print "imagepath: ", imagepath
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   136
        self.nvmemhandle = self.nvmemlib.nvmem_open( self.obj, imagepath )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   137
        if( self.nvmemhandle < 0 ):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   138
            error_msg = "syborg_nvmemorydevice: nvmem_open error: ", self.nvmemhandle
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   139
            sys.exit( error_msg )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   140
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   141
        # Initialize callback and get memory sector count
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   142
        self.initialize_nvmem_callback()
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   143
        self.nvmemory_sector_count = self.nvmemlib.nvmem_get_sector_count( self.obj, self.nvmemhandle )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   144
        print "syborg_nvmemorydevice: created\n"
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   145
            
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   146
    def updateIrq(self,new_value):
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   147
        self.set_irq_level(0, new_value)
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   148
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   149
    def nvmem_request_callback(self, result):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   150
        #print "graphics_request_callback: " , result
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   151
        self.status_reg = result
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   152
        self.updateIrq(1)
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   153
        return 0
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   154
        
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   155
    def initialize_nvmem_callback(self):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   156
        self.CALLBACKFUNC = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int)
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   157
        self.nvmem_callback = self.CALLBACKFUNC(self.nvmem_request_callback)
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   158
        self.nvmemlib.nvmem_set_callback( self.obj, self.nvmem_callback )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   159
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   160
    def read_reg(self, offset):
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   161
        offset >>= 2
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   162
        #print "read register: 0x%x" % (offset) 
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   163
        if offset == self.R_NVMEM_ID:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   164
            return 0xDEADBEEF
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   165
        elif offset == self.R_NVMEM_TRANSACTION_OFFSET:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   166
            return self.transaction_offset
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   167
        elif offset == self.R_NVMEM_TRANSACTION_SIZE:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   168
            return self.transaction_size
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   169
        elif offset == self.R_NVMEM_TRANSACTION_DIRECTION:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   170
            return self.transaction_direction
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   171
        elif offset == self.R_NVMEM_SHARED_MEMORY_BASE:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   172
            return self.shared_memory_base
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   173
        elif offset == self.R_NVMEM_SHARED_MEMORY_SIZE:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   174
            return self.shared_memory_size
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   175
        elif offset == self.R_NVMEM_NV_MEMORY_SIZE:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   176
            return self.nvmemory_sector_count
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   177
        elif offset == self.R_NVMEM_STATUS:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   178
            self.updateIrq(0)
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   179
            return self.status_reg
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   180
        else:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   181
            reg_read_error = "syborg_nvmemorydevice: Illegal register read at: ", offset 
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   182
            sys.exit( reg_read_error )
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   183
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   184
    def write_reg(self, offset, value):
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   185
        offset >>= 2
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   186
        #print "write register: 0x%x value: 0x%x" % (offset, value) 
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   187
        if offset == self.R_NVMEM_TRANSACTION_OFFSET:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   188
            self.transaction_offset = value
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   189
            self.transaction_offset_set = 1
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   190
        elif offset == self.R_NVMEM_TRANSACTION_SIZE:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   191
            self.transaction_size = value
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   192
            self.transaction_size_set = 1
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   193
        elif offset == self.R_NVMEM_TRANSACTION_DIRECTION:
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   194
            self.transaction_direction = value
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   195
            self.transaction_direction_set = 1
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   196
        elif offset == self.R_NVMEM_TRANSACTION_EXECUTE:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   197
            if( (self.transaction_offset_set == 0) | (self.transaction_size_set == 0) | (self.transaction_direction_set == 0) ):
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   198
                error_msg = "syborg_nvmemorydevice: Illegal transaction! All the required parameters are not set" 
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   199
                sys.exit( error_msg )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   200
            elif(self.transaction_size == 0 ):
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   201
                error_msg = "syborg_nvmemorydevice: Zero size transaction issued!" 
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   202
                sys.exit( error_msg )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   203
            else:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   204
                if( self.transaction_direction == self.NVMEM_TRANSACTION_READ ):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   205
                    self.nvmemlib.nvmem_read(  self.obj, self.nvmemory_sharedmemory_host_address, self.nvmemhandle, self.transaction_offset, self.transaction_size )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   206
                elif( self.transaction_direction == self.NVMEM_TRANSACTION_WRITE ):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   207
                    self.nvmemlib.nvmem_write(  self.obj, self.nvmemory_sharedmemory_host_address, self.nvmemhandle, self.transaction_offset, self.transaction_size )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   208
                else:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   209
                    error_msg = "syborg_nvmemorydevice: Transaction direction not set!" 
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   210
                    sys.exit( error_msg )
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   211
                self.transaction_offset_set = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   212
                self.transaction_size_set = 0
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   213
                self.transaction_direction_set = 0
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   214
        elif offset == self.R_NVMEM_SHARED_MEMORY_BASE:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   215
            self.shared_memory_base = value
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   216
        elif offset == self.R_NVMEM_SHARED_MEMORY_SIZE:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   217
            self.shared_memory_size = value
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   218
        elif offset == self.R_NVMEM_ENABLE:
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   219
            if( value > 0 ):
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   220
                self.nvmemory_memregion = qemu.memregion( self.shared_memory_base, self.shared_memory_size )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   221
                self.nvmemory_sharedmemory_host_address = self.nvmemory_memregion.region_host_addr()
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   222
                print"syborg_nvmemorydevice: host addr: 0x%08x" % (self.nvmemory_sharedmemory_host_address)
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   223
        else:
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   224
            reg_write_error = "syborg_nvmemorydevice: Illegal register write to: ", offset 
74
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   225
            sys.exit( reg_write_error )
eb3d0111f868 start nvmemory
jahyvone@4FIL49437
parents:
diff changeset
   226
93
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   227
    # Device class properties
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   228
    regions = [qemu.ioregion(0x1000, readl=read_reg, writel=write_reg)]
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   229
    irqs = 1
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   230
    name = "syborg,nvmemorydevice"
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   231
    properties = {"drive_size":DEFAULT_DRIVE_SIZE, "sector_size":DEVICE_SECTOR_SIZE, "drive_image_name":DRIVE_NAME}
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   232
07b904f40417 Provisional fix for bug 3508 - Persistent storage support breaks Linux compatibility.
Mike Kinghan <mikek@symbian.org>
parents: 74
diff changeset
   233
qemu.register_device(syborg_nvmemorydevice)