On Mon, 2006-08-21 at 19:34 -0400, Maria Butrico wrote:
> Summary:  Fix device tree creation for domU for js20/1 under SLOF
> 
> The device tree of dom0 on js20 and js21 with SLOF does not have the cpus'
> d and i cache sets nor does it have the l2 cache subdirectory.  

Hi Maria, please try this patch. It's a little noisy (I made printing
work for better debugging), but if it works for you I'll split it up and
check it in.

Signed-off-by: Hollis Blanchard <[EMAIL PROTECTED]>

diff -r 6eccd4911e6c tools/python/xen/xend/FlatDeviceTree.py
--- a/tools/python/xen/xend/FlatDeviceTree.py   Tue Aug 22 11:17:09 2006 -0400
+++ b/tools/python/xen/xend/FlatDeviceTree.py   Tue Aug 22 11:22:24 2006 -0500
@@ -20,8 +20,10 @@ import os
 import os
 import sys
 import struct
-
-_OF_DT_HEADER = 0xd00dfeed
+import stat
+import re
+
+_OF_DT_HEADER = int("d00dfeed", 16) # avoid signed/unsigned FutureWarning
 _OF_DT_BEGIN_NODE = 0x1
 _OF_DT_END_NODE = 0x2
 _OF_DT_PROP = 0x3
@@ -50,12 +52,40 @@ def _pad(buf, alignment):
     # not present in Python 2.3:
     #return buf.ljust(_padlen, '\0')
 
+def _indent(item):
+    indented = []
+    for line in str(item).splitlines(True):
+        indented.append('    ' + line)
+    return ''.join(indented)
+
 class _Property:
+    _nonprint = re.compile('[\000-\037\200-\377]')
     def __init__(self, node, name, value):
         self.node = node
         self.value = value
         self.name = name
         self.node.tree.stradd(name)
+
+    def __str__(self):
+        result = self.name
+        if self.value:
+            searchtext = self.value
+            # it's ok for a string to end in NULL
+            if searchtext.find('\000') == len(searchtext)-1:
+                searchtext = searchtext[:-1]
+            m = self._nonprint.search(searchtext)
+            if m:
+                bytes = struct.unpack("B" * len(self.value), self.value)
+                hexbytes = [ '%02x' % b for b in bytes ]
+                words = []
+                for i in range(0, len(self.value), 4):
+                    words.append(''.join(hexbytes[i:i+4]))
+                v = '<' + ' '.join(words) + '>'
+            else:
+                v = '"%s"' % self.value
+            result += ': ' + v
+        return result
+
     def to_bin(self):
         offset = self.node.tree.stroffset(self.name)
         return struct.pack('>III', _OF_DT_PROP, len(self.value), offset) \
@@ -68,6 +98,12 @@ class _Node:
         self.props = {}
         self.children = {}
         self.phandle = 0
+
+    def __str__(self):
+        propstrs = [ _indent(prop) for prop in self.props.values() ]
+        childstrs = [ _indent(child) for child in self.children.values() ]
+        return '%s:\n%s\n%s' % (self.name, '\n'.join(propstrs),
+            '\n'.join(childstrs))
 
     def to_bin(self):
         name = _pad(self.name + '\0', 4)
@@ -203,6 +239,22 @@ def _getprop(propname):
     f.close()
     return data
 
+def _copynode(node, dirpath, propfilter):
+    '''Extract all properties from a node in the system's device tree.'''
+    dirents = os.listdir(dirpath)
+    for dirent in dirents:
+        fullpath = os.path.join(dirpath, dirent)
+        st = os.lstat(fullpath)
+        if stat.S_ISDIR(st.st_mode):
+            child = node.addnode(dirent)
+            _copytree(child, fullpath, propfilter)
+        elif stat.S_ISREG(st.st_mode) and propfilter(fullpath):
+            node.addprop(dirent, _getprop(fullpath))
+
+def _copytree(node, dirpath, propfilter):
+    path = os.path.join(_host_devtree_root, dirpath)
+    _copynode(node, path, propfilter)
+
 def build(imghandler):
     '''Construct a device tree by combining the domain's configuration and
     the host's device tree.'''
@@ -236,33 +288,20 @@ def build(imghandler):
     cpus.addprop('#size-cells', 0)
     cpus.addprop('#address-cells', 1)
 
-    # create a cpu node for each vcpu
+    # Copy all properties the system firmware gave us, except for 'linux,'
+    # properties, from 'cpus/@0', once for every vcpu. Hopefully all cpus are
+    # identical...
     cpu0 = None
+    def _nolinuxprops(fullpath):
+        if os.path.basename(fullpath).startswith('linux,'):
+            return False
+        return True
     for i in range(imghandler.vm.getVCpuCount()):
         cpu = cpus.addnode('PowerPC,[EMAIL PROTECTED]')
+        _copytree(cpu, 'cpus/PowerPC,[EMAIL PROTECTED]', _nolinuxprops)
+        # and then overwrite what we need to
         pft_size = imghandler.vm.info.get('pft-size', 0x14)
-        cpu.addprop('ibm,pft-size', 0, pft_size)
-        cpu.addprop('reg', i)
-        cpu.addprop('cpu#', i)
-        cpu.addprop('device_type', 'cpu\0')
-        for prop in ('d-cache-size', 'd-cache-line-size', 'd-cache-sets',
-                     'i-cache-size', 'i-cache-line-size', 'i-cache-sets',
-                     'clock-frequency', 'timebase-frequency',
-                     'timebases-in-sync'):
-            val = _getprop(os.path.join('cpus/PowerPC,[EMAIL PROTECTED]', 
prop))
-            cpu.addprop(prop, val)
-            # XXX 64-bit, more
-
-        # L2 cache
-        l2 = cpu.addnode('l2-cache')
-        l2.addprop('name', 'l2-cache\0')
-        l2.addprop('device_type', 'cache\0')
-        for prop in ('d-cache-size', 'd-cache-sets',
-                     'i-cache-size', 'i-cache-sets',
-                     'cache-unified'):
-            fullprop = os.path.join('cpus/PowerPC,[EMAIL PROTECTED]/l2-cache' 
% i, prop)
-            val = _getprop(fullprop)
-            l2.addprop(prop, val)
+        cpu.setprop('ibm,pft-size', 0, pft_size)
 
         # set default CPU
         if cpu0 == None:


-- 
Hollis Blanchard
IBM Linux Technology Center


_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel

Reply via email to