5 files changed, 48 insertions(+), 376 deletions(-)
tools/python/xen/xend/FlatDeviceTree.py | 359 -------------------------------
tools/libxc/powerpc64/xc_prose_build.c | 44 +++
tools/libxc/xenguest.h | 3
tools/python/xen/lowlevel/xc/xc.c | 12 -
tools/python/xen/xend/image.py | 6
# HG changeset patch
# User Ryan Harper <ryanh@xxxxxxxxxx>
# Date 1168544367 21600
# Node ID a2ff54d361f5853ff83adedfe0d7bbc63363bfdc
# Parent e4fda6c5e7a907b5e4726c4f4d5f117c0f4d6f50
[PATCH] Remove FlatDeviceTree.py, move prose builder to libxc devtree
construction.
Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
diff -r e4fda6c5e7a9 -r a2ff54d361f5 tools/libxc/powerpc64/xc_prose_build.c
--- a/tools/libxc/powerpc64/xc_prose_build.c Thu Jan 11 13:39:27 2007 -0600
+++ b/tools/libxc/powerpc64/xc_prose_build.c Thu Jan 11 13:39:27 2007 -0600
@@ -13,10 +13,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * Copyright (C) IBM Corporation 2006
+ * Copyright IBM Corporation 2006
*
* Authors: Hollis Blanchard <hollisb@xxxxxxxxxx>
* Jonathan Appavoo <jappavoo@xxxxxxxxxx>
+ * Ryan Harper <ryanh@xxxxxxxxxx>
*/
#include <stdio.h>
@@ -37,6 +38,7 @@
#include "flatdevtree_env.h"
#include "flatdevtree.h"
#include "utils.h"
+#include "mk_flatdevtree.h"
#define INITRD_ADDR (24UL << 20)
#define DEVTREE_ADDR (16UL << 20)
@@ -239,8 +241,7 @@ int xc_prose_build(int xc_handle,
unsigned int store_evtchn,
unsigned long *store_mfn,
unsigned int console_evtchn,
- unsigned long *console_mfn,
- void *devtree)
+ unsigned long *console_mfn)
{
start_info_t start_info;
struct domain_setup_info dsi;
@@ -252,7 +253,13 @@ int xc_prose_build(int xc_handle,
unsigned long initrd_len = 0;
unsigned long start_info_addr;
unsigned long rma_pages;
+ unsigned long shadow_mb;
int rc = 0;
+ int op;
+ uint32_t nr_vcpus;
+ xc_dominfo_t info;
+ struct ft_cxt root;
+ void *devtree;
DPRINTF("%s\n", __func__);
@@ -260,6 +267,36 @@ int xc_prose_build(int xc_handle,
nr_pages = mem_mb << (20 - PAGE_SHIFT);
DPRINTF("nr_pages 0x%lx\n", nr_pages);
+
+ /* XXX: fetch the number of vcpus configured for this domain
+ checking that xc_domain_getinfo returns info for exactly 1
+ dom */
+ if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
+ DPRINTF("xc_domain_getinfo() failed, can't determine max_vcpu_id\n");
+ rc = -1;
+ goto out;
+ }
+
+ /* NB: max_vcpu_id is zero-based */
+ nr_vcpus = info.max_vcpu_id + 1;
+
+ /* XXX: fetch the current shadow_memory value for this domain */
+ op = XEN_DOMCTL_SHADOW_OP_GET_ALLOCATION;
+ if (xc_shadow_control(xc_handle, domid, op, NULL, 0, &shadow_mb, 0, NULL)
< 0 ) {
+ rc = -1;
+ goto out;
+ }
+
+ /* build the devtree here */
+ DPRINTF("constructing devtree\n");
+ if (make_devtree(&root, domid, mem_mb, nr_vcpus, shadow_mb, cmdline) < 0) {
+ DPRINTF("failed to create flattened device tree\n");
+ rc = -1;
+ goto out;
+ }
+
+ /* point devtree at bph blob */
+ devtree = root.bph;
rma_pages = get_rma_pages(devtree);
if (rma_pages == 0) {
@@ -318,6 +355,7 @@ int xc_prose_build(int xc_handle,
}
out:
+ free_devtree(root.bph);
free_page_array(page_array);
return rc;
}
diff -r e4fda6c5e7a9 -r a2ff54d361f5 tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h Thu Jan 11 13:39:27 2007 -0600
+++ b/tools/libxc/xenguest.h Thu Jan 11 13:39:27 2007 -0600
@@ -138,7 +138,6 @@ int xc_prose_build(int xc_handle,
unsigned int store_evtchn,
unsigned long *store_mfn,
unsigned int console_evtchn,
- unsigned long *console_mfn,
- void *arch_args);
+ unsigned long *console_mfn);
#endif /* XENGUEST_H */
diff -r e4fda6c5e7a9 -r a2ff54d361f5 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Thu Jan 11 13:39:27 2007 -0600
+++ b/tools/python/xen/lowlevel/xc/xc.c Thu Jan 11 13:39:27 2007 -0600
@@ -378,28 +378,26 @@ static PyObject *pyxc_prose_build(XcObje
unsigned int mem_mb;
unsigned long store_mfn = 0;
unsigned long console_mfn = 0;
- void *arch_args = NULL;
int unused;
static char *kwd_list[] = { "dom", "store_evtchn", "memsize",
"console_evtchn", "image",
/* optional */
"ramdisk", "cmdline", "flags",
- "features", "arch_args", NULL };
-
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssiss#", kwd_list,
+ "features", NULL };
+
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiis|ssis#", kwd_list,
&dom, &store_evtchn, &mem_mb,
&console_evtchn, &image,
/* optional */
&ramdisk, &cmdline, &flags,
- &features, &arch_args, &unused) )
+ &features, &unused) )
return NULL;
if ( xc_prose_build(self->xc_handle, dom, mem_mb, image,
ramdisk, cmdline, features, flags,
store_evtchn, &store_mfn,
- console_evtchn, &console_mfn,
- arch_args) != 0 ) {
+ console_evtchn, &console_mfn) != 0 ) {
if (!errno)
errno = EINVAL;
return PyErr_SetFromErrno(xc_error);
diff -r e4fda6c5e7a9 -r a2ff54d361f5 tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py Thu Jan 11 13:39:27 2007 -0600
+++ b/tools/python/xen/xend/image.py Thu Jan 11 13:39:27 2007 -0600
@@ -29,7 +29,6 @@ from xen.xend.server.netif import random
from xen.xend.server.netif import randomMAC
from xen.xend.xenstore.xswatch import xswatch
from xen.xend import arch
-from xen.xend import FlatDeviceTree
xc = xen.lowlevel.xc.xc()
@@ -276,8 +275,6 @@ class PPC_ProseImageHandler(LinuxImageHa
log.debug("vcpus = %d", self.vm.getVCpuCount())
log.debug("features = %s", self.vm.getFeatures())
- devtree = FlatDeviceTree.build(self)
-
return xc.prose_build(dom = self.vm.getDomid(),
memsize = mem_mb,
image = self.kernel,
@@ -285,8 +282,7 @@ class PPC_ProseImageHandler(LinuxImageHa
console_evtchn = console_evtchn,
cmdline = self.cmdline,
ramdisk = self.ramdisk,
- features = self.vm.getFeatures(),
- arch_args = devtree.to_bin())
+ features = self.vm.getFeatures())
def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
"""@param shadow_mem_kb The configured shadow memory, in KiB.
diff -r e4fda6c5e7a9 -r a2ff54d361f5 tools/python/xen/xend/FlatDeviceTree.py
--- a/tools/python/xen/xend/FlatDeviceTree.py Thu Jan 11 13:39:27 2007 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,359 +0,0 @@
-#!/usr/bin/env python
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of version 2.1 of the GNU Lesser General Public
-# License as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# Copyright (C) IBM Corp. 2006
-#
-# Authors: Hollis Blanchard <hollisb@xxxxxxxxxx>
-
-import os
-import sys
-import struct
-import stat
-import re
-import glob
-import math
-
-_host_devtree_root = '/proc/device-tree'
-
-_OF_DT_HEADER = int("d00dfeed", 16) # avoid signed/unsigned FutureWarning
-_OF_DT_BEGIN_NODE = 0x1
-_OF_DT_END_NODE = 0x2
-_OF_DT_PROP = 0x3
-_OF_DT_END = 0x9
-
-def _bincat(seq, separator=''):
- '''Concatenate the contents of seq into a bytestream.'''
- strs = []
- for item in seq:
- if isinstance(item, int):
- strs.append(struct.pack(">I", item))
- elif isinstance(item, long):
- strs.append(struct.pack(">Q", item))
- else:
- try:
- strs.append(item.to_bin())
- except AttributeError, e:
- strs.append(item)
- return separator.join(strs)
-
-def _alignup(val, alignment):
- return (val + alignment - 1) & ~(alignment - 1)
-
-def _pad(buf, alignment):
- '''Pad bytestream with NULLs to specified alignment.'''
- padlen = _alignup(len(buf), alignment)
- return buf + '\0' * (padlen - len(buf))
- # 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) \
- + _pad(self.value, 4)
-
-class _Node:
- def __init__(self, tree, name):
- self.tree = tree
- self.name = name
- 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)
- return struct.pack('>I', _OF_DT_BEGIN_NODE) + \
- name + \
- _bincat(self.props.values()) + \
- _bincat(self.children.values()) + \
- struct.pack('>I', _OF_DT_END_NODE)
-
- def addprop(self, propname, *cells):
- '''setprop with duplicate error-checking.'''
- if propname in self.props:
- raise AttributeError('%s/%s already exists' % (self.name,
propname))
- self.setprop(propname, *cells)
-
- def setprop(self, propname, *cells):
- self.props[propname] = _Property(self, propname, _bincat(cells))
-
- def addnode(self, nodename):
- '''newnode with duplicate error-checking.'''
- if nodename in self.children:
- raise AttributeError('%s/%s already exists' % (self.name,
nodename))
- return self.newnode(nodename)
-
- def newnode(self, nodename):
- node = _Node(self.tree, nodename)
- self.children[nodename] = node
- return node
-
- def getprop(self, propname):
- return self.props[propname]
-
- def getchild(self, nodename):
- return self.children[nodename]
-
- def get_phandle(self):
- if self.phandle:
- return self.phandle
- self.phandle = self.tree.alloc_phandle()
- self.addprop('linux,phandle', self.phandle)
- return self.phandle
-
-class _Header:
- def __init__(self):
- self.magic = 0
- self.totalsize = 0
- self.off_dt_struct = 0
- self.off_dt_strings = 0
- self.off_mem_rsvmap = 0
- self.version = 0
- self.last_comp_version = 0
- self.boot_cpuid_phys = 0
- self.size_dt_strings = 0
- def to_bin(self):
- return struct.pack('>9I',
- self.magic,
- self.totalsize,
- self.off_dt_struct,
- self.off_dt_strings,
- self.off_mem_rsvmap,
- self.version,
- self.last_comp_version,
- self.boot_cpuid_phys,
- self.size_dt_strings)
-
-class _StringBlock:
- def __init__(self):
- self.table = []
- def to_bin(self):
- return _bincat(self.table, '\0') + '\0'
- def add(self, str):
- self.table.append(str)
- def getoffset(self, str):
- return self.to_bin().index(str + '\0')
-
-class Tree(_Node):
- def __init__(self):
- self.last_phandle = 0
- self.strings = _StringBlock()
- self.reserved = [(0, 0)]
- _Node.__init__(self, self, '\0')
-
- def alloc_phandle(self):
- self.last_phandle += 1
- return self.last_phandle
-
- def stradd(self, str):
- return self.strings.add(str)
-
- def stroffset(self, str):
- return self.strings.getoffset(str)
-
- def reserve(self, start, len):
- self.reserved.insert(0, (start, len))
-
- def to_bin(self):
- # layout:
- # header
- # reservation map
- # string block
- # data block
-
- datablock = _Node.to_bin(self)
-
- r = [ struct.pack('>QQ', rsrv[0], rsrv[1]) for rsrv in self.reserved ]
- reserved = _bincat(r)
-
- strblock = _pad(self.strings.to_bin(), 4)
- strblocklen = len(strblock)
-
- header = _Header()
- header.magic = _OF_DT_HEADER
- header.off_mem_rsvmap = _alignup(len(header.to_bin()), 8)
- header.off_dt_strings = header.off_mem_rsvmap + len(reserved)
- header.off_dt_struct = header.off_dt_strings + strblocklen
- header.version = 0x10
- header.last_comp_version = 0x10
- header.boot_cpuid_phys = 0
- header.size_dt_strings = strblocklen
-
- payload = reserved + \
- strblock + \
- datablock + \
- struct.pack('>I', _OF_DT_END)
- header.totalsize = len(payload) + _alignup(len(header.to_bin()), 8)
- return _pad(header.to_bin(), 8) + payload
-
-def _readfile(fullpath):
- '''Return full contents of a file.'''
- f = file(fullpath, 'r')
- data = f.read()
- f.close()
- return data
-
-def _find_first_cpu(dirpath):
- '''Find the first node of type 'cpu' in a directory tree.'''
- cpulist = glob.glob(os.path.join(dirpath, 'cpus', '*'))
- for node in cpulist:
- try:
- data = _readfile(os.path.join(node, 'device_type'))
- except IOError:
- continue
- if 'cpu' in data:
- return node
- raise IOError("couldn't find any CPU nodes under " + dirpath)
-
-def _copynode(node, dirpath, propfilter):
- '''Copy all properties and children nodes from a directory 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)
- _copynode(child, fullpath, propfilter)
- elif stat.S_ISREG(st.st_mode) and propfilter(fullpath):
- node.addprop(dirent, _readfile(fullpath))
-
-def build(imghandler):
- '''Construct a device tree by combining the domain's configuration and
- the host's device tree.'''
- root = Tree()
-
- # 1st reseravtion entry used for start_info, console, store, shared_info
- root.reserve(0x3ffc000, 0x4000)
-
- # 2nd reservation enrty used for initrd, later on when we load the
- # initrd we may fill this in with zeroes which signifies the end
- # of the reservation map. So as to avoid adding a zero map now we
- # put some bogus yet sensible numbers here.
- root.reserve(0x1000000, 0x1000)
-
- root.addprop('device_type', 'chrp-but-not-really\0')
- root.addprop('#size-cells', 2)
- root.addprop('#address-cells', 2)
- root.addprop('model', 'Momentum,Maple-D\0')
- root.addprop('compatible', 'Momentum,Maple\0')
-
- xen = root.addnode('xen')
- xen.addprop('start-info', long(0x3ffc000), long(0x1000))
- xen.addprop('version', 'Xen-3.0-unstable\0')
- xen.addprop('reg', long(imghandler.vm.domid), long(0))
- xen.addprop('domain-name', imghandler.vm.getName() + '\0')
- xencons = xen.addnode('console')
- xencons.addprop('interrupts', 1, 0)
-
- # add memory nodes
- totalmem = imghandler.vm.getMemoryTarget() * 1024
- rma_log = 26 ### imghandler.vm.info.get('powerpc_rma_log')
- rma_bytes = 1 << rma_log
-
- # RMA node
- rma = root.addnode('memory@0')
- rma.addprop('reg', long(0), long(rma_bytes))
- rma.addprop('device_type', 'memory\0')
-
- # all the rest in a single node
- remaining = totalmem - rma_bytes
- if remaining > 0:
- mem = root.addnode('memory@1')
- mem.addprop('reg', long(rma_bytes), long(remaining))
- mem.addprop('device_type', 'memory\0')
-
- # add CPU nodes
- cpus = root.addnode('cpus')
- cpus.addprop('smp-enabled')
- cpus.addprop('#size-cells', 0)
- cpus.addprop('#address-cells', 1)
-
- # Copy all properties the system firmware gave us, except for 'linux,'
- # properties, from the first CPU node in the device tree. Do this once for
- # every vcpu. Hopefully all cpus are identical...
- cpu0 = None
- cpu0path = _find_first_cpu(_host_devtree_root)
- def _nolinuxprops(fullpath):
- return not os.path.basename(fullpath).startswith('linux,')
- for i in range(imghandler.vm.getVCpuCount()):
- # create new node and copy all properties
- cpu = cpus.addnode('PowerPC,970@%d' % i)
- _copynode(cpu, cpu0path, _nolinuxprops)
-
- # overwrite what we need to
- shadow_mb = imghandler.vm.info.get('shadow_memory', 1)
- shadow_mb_log = int(math.log(shadow_mb, 2))
- pft_size = shadow_mb_log + 20
- cpu.setprop('ibm,pft-size', 0, pft_size)
-
- # set default CPU
- if cpu0 == None:
- cpu0 = cpu
-
- chosen = root.addnode('chosen')
- chosen.addprop('cpu', cpu0.get_phandle())
- chosen.addprop('memory', rma.get_phandle())
- chosen.addprop('linux,stdout-path', '/xen/console\0')
- chosen.addprop('interrupt-controller', xen.get_phandle())
- chosen.addprop('bootargs', imghandler.cmdline + '\0')
- # xc_linux_load.c will overwrite these 64-bit properties later
- chosen.addprop('linux,initrd-start', long(0))
- chosen.addprop('linux,initrd-end', long(0))
-
- if 1:
- f = file('/tmp/domU.dtb', 'w')
- f.write(root.to_bin())
- f.close()
-
- return root
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|