# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 28ce48573771c0f7b07a931dcc35011c7c942af7
# Parent 6a2acc1cc505a9553d148517a83ef02921441167
# Parent 58d46463413ec97caa0c4301a3d2d350747a5dc5
Merged.
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32
--- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 Wed Nov
30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 Wed Nov
30 19:55:08 2005
@@ -432,7 +432,7 @@
CONFIG_IOSCHED_AS=y
CONFIG_IOSCHED_DEADLINE=y
CONFIG_IOSCHED_CFQ=y
-# CONFIG_ATA_OVER_ETH is not set
+CONFIG_ATA_OVER_ETH=m
#
# ATA/ATAPI/MFM/RLL support
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Wed Nov 30
19:55:08 2005
@@ -88,10 +88,10 @@
* handle returned must be used to unmap the frame. This is needed to
* drop the ref count on the frame.
*/
-static u16 pending_grant_handles[MMAP_PAGES];
+static grant_handle_t pending_grant_handles[MMAP_PAGES];
#define pending_handle(_idx, _i) \
(pending_grant_handles[((_idx) * BLKIF_MAX_SEGMENTS_PER_REQUEST) + (_i)])
-#define BLKBACK_INVALID_HANDLE (0xFFFF)
+#define BLKBACK_INVALID_HANDLE (~0)
#ifdef CONFIG_XEN_BLKDEV_TAP_BE
/*
@@ -114,7 +114,7 @@
{
struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
unsigned int i, invcount = 0;
- u16 handle;
+ grant_handle_t handle;
int ret;
for (i = 0; i < nr_pages; i++) {
@@ -335,7 +335,6 @@
{
extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]);
int operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
- unsigned long fas = 0;
int i, pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
pending_req_t *pending_req;
struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
@@ -362,16 +361,17 @@
preq.nr_sects = 0;
for (i = 0; i < nseg; i++) {
- fas = req->frame_and_sects[i];
- seg[i].nsec = blkif_last_sect(fas) - blkif_first_sect(fas) + 1;
-
- if (seg[i].nsec <= 0)
+ seg[i].nsec = req->seg[i].last_sect -
+ req->seg[i].first_sect + 1;
+
+ if ((req->seg[i].last_sect >= (PAGE_SIZE >> 9)) ||
+ (seg[i].nsec <= 0))
goto bad_descriptor;
preq.nr_sects += seg[i].nsec;
map[i].host_addr = MMAP_VADDR(pending_idx, i);
map[i].dom = blkif->domid;
- map[i].ref = blkif_gref_from_fas(fas);
+ map[i].ref = req->seg[i].gref;
map[i].flags = GNTMAP_host_map;
if ( operation == WRITE )
map[i].flags |= GNTMAP_readonly;
@@ -381,7 +381,7 @@
BUG_ON(ret);
for (i = 0; i < nseg; i++) {
- if (likely(map[i].handle >= 0)) {
+ if (likely(map[i].status == 0)) {
pending_handle(pending_idx, i) = map[i].handle;
#ifdef __ia64__
MMAP_VADDR(pending_idx,i) = gnttab_map_vaddr(map[i]);
@@ -390,9 +390,8 @@
pending_idx, i)) >> PAGE_SHIFT,
FOREIGN_FRAME(map[i].dev_bus_addr>>PAGE_SHIFT));
#endif
- fas = req->frame_and_sects[i];
- seg[i].buf = map[i].dev_bus_addr |
- (blkif_first_sect(fas) << 9);
+ seg[i].buf = map[i].dev_bus_addr |
+ (req->seg[i].first_sect << 9);
} else {
errors++;
}
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blkback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Wed Nov 30 19:55:08 2005
@@ -66,8 +66,8 @@
struct work_struct free_work;
- u16 shmem_handle;
- grant_ref_t shmem_ref;
+ grant_handle_t shmem_handle;
+ grant_ref_t shmem_ref;
} blkif_t;
blkif_t *alloc_blkif(domid_t domid);
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Wed Nov 30
19:55:08 2005
@@ -43,9 +43,9 @@
unlock_vm_area(blkif->blk_ring_area);
BUG_ON(ret);
- if (op.handle < 0) {
+ if (op.status) {
DPRINTK(" Grant table operation failure !\n");
- return op.handle;
+ return op.status;
}
blkif->shmem_ref = shared_page;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Wed Nov 30
19:55:08 2005
@@ -32,7 +32,6 @@
* IN THE SOFTWARE.
*/
-
#if 1
#define ASSERT(p) \
if (!(p)) { printk("Assertion '%s' failed, line %d, file %s", #p , \
@@ -40,7 +39,6 @@
#else
#define ASSERT(_p)
#endif
-
#include <linux/version.h>
#include "block.h"
@@ -54,15 +52,13 @@
#include <asm-xen/gnttab.h>
#include <asm/hypervisor.h>
-
#define BLKIF_STATE_DISCONNECTED 0
#define BLKIF_STATE_CONNECTED 1
#define BLKIF_STATE_SUSPENDED 2
#define MAXIMUM_OUTSTANDING_BLOCK_REQS \
- (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
+ (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLK_RING_SIZE)
#define GRANT_INVALID_REF 0
-
static void connect(struct blkfront_info *);
static void blkfront_closing(struct xenbus_device *);
@@ -551,8 +547,11 @@
info->shadow[id].frame[ring_req->nr_segments] =
mfn_to_pfn(buffer_mfn);
- ring_req->frame_and_sects[ring_req->nr_segments] =
- blkif_fas_from_gref(ref, fsect, lsect);
+ ring_req->seg[ring_req->nr_segments] =
+ (struct blkif_request_segment) {
+ .gref = ref,
+ .first_sect = fsect,
+ .last_sect = lsect };
ring_req->nr_segments++;
}
@@ -699,8 +698,7 @@
{
int i;
for (i = 0; i < s->req.nr_segments; i++)
- gnttab_end_foreign_access(
- blkif_gref_from_fas(s->req.frame_and_sects[i]), 0, 0UL);
+ gnttab_end_foreign_access(s->req.seg[i].gref, 0, 0UL);
}
static void blkif_recover(struct blkfront_info *info)
@@ -740,7 +738,7 @@
/* Rewrite any grant references invalidated by susp/resume. */
for (j = 0; j < req->nr_segments; j++)
gnttab_grant_foreign_access_ref(
- blkif_gref_from_fas(req->frame_and_sects[j]),
+ req->seg[j].gref,
info->xbdev->otherend_id,
pfn_to_mfn(info->shadow[req->id].frame[j]),
rq_data_dir(
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Wed Nov 30 19:55:08 2005
@@ -32,6 +32,9 @@
#include "block.h"
#include <linux/blkdev.h>
#include <linux/list.h>
+
+#define BLKIF_MAJOR(dev) ((dev)>>8)
+#define BLKIF_MINOR(dev) ((dev) & 0xff)
/*
* For convenience we distinguish between ide, scsi and 'other' (i.e.,
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c Wed Nov 30 19:55:08 2005
@@ -177,8 +177,8 @@
*/
struct grant_handle_pair
{
- u16 kernel;
- u16 user;
+ grant_handle_t kernel;
+ grant_handle_t user;
};
static struct grant_handle_pair pending_grant_handles[MMAP_PAGES];
#define pending_handle(_idx, _i) \
@@ -713,7 +713,7 @@
/* Map the remote page to kernel. */
map[op].host_addr = kvaddr;
map[op].dom = blkif->domid;
- map[op].ref = blkif_gref_from_fas(req->frame_and_sects[i]);
+ map[op].ref = req->seg[i].gref;
map[op].flags = GNTMAP_host_map;
/* This needs a bit more thought in terms of interposition:
* If we want to be able to modify pages during write using
@@ -733,7 +733,7 @@
map[op].host_addr = ptep;
map[op].dom = blkif->domid;
- map[op].ref =
blkif_gref_from_fas(req->frame_and_sects[i]);
+ map[op].ref = req->seg[i].gref;
map[op].flags = GNTMAP_host_map | GNTMAP_application_map
| GNTMAP_contains_pte;
/* Above interposition comment applies here as well. */
@@ -755,17 +755,17 @@
uvaddr = MMAP_VADDR(user_vstart, pending_idx, i/2);
kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i/2);
- if (unlikely(map[i].handle < 0)) {
+ if (unlikely(map[i].status)) {
DPRINTK("Error on kernel grant mapping (%d)\n",
- map[i].handle);
- ret = map[i].handle;
+ map[i].status);
+ ret = map[i].status;
cancel = 1;
}
- if (unlikely(map[i+1].handle < 0)) {
+ if (unlikely(map[i+1].status)) {
DPRINTK("Error on user grant mapping (%d)\n",
- map[i+1].handle);
- ret = map[i+1].handle;
+ map[i+1].status);
+ ret = map[i+1].status;
cancel = 1;
}
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blktap/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h Wed Nov 30 19:55:08 2005
@@ -64,7 +64,7 @@
struct work_struct free_work;
- u16 shmem_handle;
+ grant_handle_t shmem_handle;
grant_ref_t shmem_ref;
} blkif_t;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c Wed Nov 30
19:55:08 2005
@@ -43,9 +43,9 @@
unlock_vm_area(blkif->blk_ring_area);
BUG_ON(ret);
- if (op.handle < 0) {
+ if (op.status) {
DPRINTK(" Grant table operation failure !\n");
- return op.handle;
+ return op.status;
}
blkif->shmem_ref = shared_page;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/netback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h Wed Nov 30 19:55:08 2005
@@ -45,9 +45,9 @@
u8 fe_dev_addr[6];
/* Physical parameters of the comms window. */
- u16 tx_shmem_handle;
+ grant_handle_t tx_shmem_handle;
grant_ref_t tx_shmem_ref;
- u16 rx_shmem_handle;
+ grant_handle_t rx_shmem_handle;
grant_ref_t rx_shmem_ref;
unsigned int evtchn;
unsigned int irq;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c Wed Nov 30
19:55:08 2005
@@ -127,9 +127,9 @@
unlock_vm_area(netif->comms_area);
BUG_ON(ret);
- if (op.handle < 0) {
+ if (op.status) {
DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
- return op.handle;
+ return op.status;
}
netif->tx_shmem_ref = tx_ring_ref;
@@ -145,9 +145,9 @@
unlock_vm_area(netif->comms_area);
BUG_ON(ret);
- if (op.handle < 0) {
+ if (op.status) {
DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
- return op.handle;
+ return op.status;
}
netif->rx_shmem_ref = rx_ring_ref;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Wed Nov 30
19:55:08 2005
@@ -68,7 +68,7 @@
static struct sk_buff_head tx_queue;
-static u16 grant_tx_ref[MAX_PENDING_REQS];
+static grant_handle_t grant_tx_handle[MAX_PENDING_REQS];
static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
@@ -412,7 +412,7 @@
pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
gop->host_addr = MMAP_VADDR(pending_idx);
gop->dev_bus_addr = 0;
- gop->handle = grant_tx_ref[pending_idx];
+ gop->handle = grant_tx_handle[pending_idx];
gop++;
}
ret = HYPERVISOR_grant_table_op(
@@ -592,7 +592,7 @@
sizeof(txreq));
/* Check the remap error code. */
- if (unlikely(mop->handle < 0)) {
+ if (unlikely(mop->status)) {
printk(KERN_ALERT "#### netback grant fails\n");
make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
netif_put(netif);
@@ -605,7 +605,7 @@
set_phys_to_machine(
__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
- grant_tx_ref[pending_idx] = mop->handle;
+ grant_tx_handle[pending_idx] = mop->handle;
data_len = (txreq.size > PKT_PROT_LEN) ?
PKT_PROT_LEN : txreq.size;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/tpmback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h Wed Nov 30 19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h Wed Nov 30 19:55:08 2005
@@ -54,7 +54,7 @@
struct work_struct work;
- u16 shmem_handle;
+ grant_handle_t shmem_handle;
grant_ref_t shmem_ref;
} tpmif_t;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Wed Nov 30
19:55:08 2005
@@ -91,9 +91,9 @@
unlock_vm_area(tpmif->tx_area);
BUG_ON(ret);
- if (op.handle < 0) {
+ if (op.status) {
DPRINTK(" Grant table operation failure !\n");
- return op.handle;
+ return op.status;
}
tpmif->shmem_ref = shared_page;
diff -r 6a2acc1cc505 -r 28ce48573771
linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Wed Nov 30
19:54:28 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Wed Nov 30
19:55:08 2005
@@ -249,7 +249,7 @@
* and send it to the front end.
*/
tpmif_t *tpmif = pak->tpmif;
- u16 handle;
+ grant_handle_t handle;
int rc = 0;
unsigned int i = 0;
unsigned int offset = 0;
@@ -290,7 +290,7 @@
handle = map_op.handle;
- if (map_op.handle < 0) {
+ if (map_op.status) {
DPRINTK(" Grant table operation failure !\n");
return 0;
}
@@ -427,7 +427,7 @@
u32 i = (last_read / PAGE_SIZE);
u32 pg_offset = last_read & (PAGE_SIZE - 1);
u32 to_copy;
- u16 handle;
+ grant_handle_t handle;
tpmif_tx_request_t *tx;
tx = &tpmif->tx->ring[0].req;
@@ -455,7 +455,7 @@
BUG();
}
- if (map_op.handle < 0) {
+ if (map_op.status) {
DPRINTK(" Grant table operation failure !\n");
return -EFAULT;
}
diff -r 6a2acc1cc505 -r 28ce48573771 tools/blktap/blkdump.c
--- a/tools/blktap/blkdump.c Wed Nov 30 19:54:28 2005
+++ b/tools/blktap/blkdump.c Wed Nov 30 19:55:08 2005
@@ -11,7 +11,6 @@
int request_print(blkif_request_t *req)
{
int i;
- unsigned long fas;
if ( (req->operation == BLKIF_OP_READ) ||
(req->operation == BLKIF_OP_WRITE) )
@@ -24,12 +23,10 @@
for (i=0; i < req->nr_segments; i++) {
- fas = req->frame_and_sects[i];
- printf(" (pf: 0x%8lx start: %lu stop: %lu)\n",
- (fas & PAGE_MASK),
- blkif_first_sect(fas),
- blkif_last_sect(fas)
- );
+ printf(" (gref: 0x%8x start: %u stop: %u)\n",
+ req->seg[i].gref,
+ req->seg[i].first_sect,
+ req->seg[i].last_sect);
}
} else {
diff -r 6a2acc1cc505 -r 28ce48573771 tools/blktap/blktaplib.c
--- a/tools/blktap/blktaplib.c Wed Nov 30 19:54:28 2005
+++ b/tools/blktap/blktaplib.c Wed Nov 30 19:55:08 2005
@@ -244,8 +244,8 @@
RING_IDX rp, i, pfd_count;
/* pending rings */
- blkif_request_t req_pending[BLKIF_RING_SIZE];
- /* blkif_response_t rsp_pending[BLKIF_RING_SIZE] */;
+ blkif_request_t req_pending[BLK_RING_SIZE];
+ /* blkif_response_t rsp_pending[BLK_RING_SIZE] */;
/* handler hooks: */
request_hook_t *req_hook;
diff -r 6a2acc1cc505 -r 28ce48573771 tools/blktap/blktaplib.h
--- a/tools/blktap/blktaplib.h Wed Nov 30 19:54:28 2005
+++ b/tools/blktap/blktaplib.h Wed Nov 30 19:55:08 2005
@@ -18,11 +18,13 @@
#include <xen/io/domain_controller.h>
#include <xs.h>
+#define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
+
/* /dev/xen/blktap resides at device number major=10, minor=202 */
#define BLKTAP_MINOR 202
/* size of the extra VMA area to map in attached pages. */
-#define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
+#define BLKTAP_VMA_PAGES BLK_RING_SIZE
/* blktap IOCTLs: */
#define BLKTAP_IOCTL_KICK_FE 1
diff -r 6a2acc1cc505 -r 28ce48573771 tools/blktap/parallax/parallax.c
--- a/tools/blktap/parallax/parallax.c Wed Nov 30 19:54:28 2005
+++ b/tools/blktap/parallax/parallax.c Wed Nov 30 19:55:08 2005
@@ -280,8 +280,7 @@
goto err;
/* Make sure the buffer is page-sized. */
- if ( (blkif_first_sect(req->frame_and_sects[0]) != 0) ||
- (blkif_last_sect (req->frame_and_sects[0]) != 7) )
+ if ( (req->seg[0].first_sect != 0) || (req->seg[0].last_sect != 7) )
goto err;
/* fill the list of devices */
@@ -350,17 +349,16 @@
/* Calculate read size and offset within the read block. */
offset = (param->sector << SECTOR_SHIFT) % BLOCK_SIZE;
- size = ( blkif_last_sect (req->frame_and_sects[segment]) -
- blkif_first_sect(req->frame_and_sects[segment]) + 1
- ) << SECTOR_SHIFT;
- start = blkif_first_sect(req->frame_and_sects[segment])
- << SECTOR_SHIFT;
+ size = (req->seg[segment].last_sect - req->seg[segment].first_sect + 1) <<
+ SECTOR_SHIFT;
+ start = req->seg[segment].first_sect << SECTOR_SHIFT;
DPRINTF("ParallaxRead: sect: %lld (%ld,%ld), "
"vblock %llx, "
"size %lx\n",
- param->sector, blkif_first_sect(p->req->frame_and_sects[segment]),
- blkif_last_sect (p->req->frame_and_sects[segment]),
+ param->sector,
+ p->req->seg[segment].first_sect,
+ p->req->seg[segment].last_sect,
param->vblock, size);
memcpy(dpage + start, spage + offset, size);
@@ -506,16 +504,15 @@
/* Calculate read size and offset within the read block. */
offset = (sector << SECTOR_SHIFT) % BLOCK_SIZE;
- size = ( blkif_last_sect (req->frame_and_sects[i]) -
- blkif_first_sect(req->frame_and_sects[i]) + 1
- ) << SECTOR_SHIFT;
- start = blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
+ size = (req->seg[i].last_sect - req->seg[i].first_sect + 1) <<
+ SECTOR_SHIFT;
+ start = req->seg[i].first_sect << SECTOR_SHIFT;
DPRINTF("ParallaxWrite: sect: %lld (%ld,%ld), "
"vblock %llx, gblock %llx, "
"size %lx\n",
- sector, blkif_first_sect(req->frame_and_sects[i]),
- blkif_last_sect (req->frame_and_sects[i]),
+ sector,
+ req->seg[i].first_sect, req->seg[i].last_sect,
vblock, gblock, size);
/* XXX: For now we just freak out if they try to write a */
diff -r 6a2acc1cc505 -r 28ce48573771 tools/blktap/ublkback/ublkbacklib.c
--- a/tools/blktap/ublkback/ublkbacklib.c Wed Nov 30 19:54:28 2005
+++ b/tools/blktap/ublkback/ublkbacklib.c Wed Nov 30 19:55:08 2005
@@ -233,8 +233,7 @@
case BLKIF_OP_WRITE:
{
unsigned long size;
-
-
+
batch_count++;
idx = ID_TO_IDX(req->id);
@@ -247,18 +246,17 @@
sector = req->sector_number + (8*i);
- size = blkif_last_sect (req->frame_and_sects[i]) -
- blkif_first_sect(req->frame_and_sects[i]) + 1;
-
- if (blkif_first_sect(req->frame_and_sects[i]) != 0)
- DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) pos: %15lu\n",
- req->sector_number, sector,
- blkif_first_sect(req->frame_and_sects[i]),
- blkif_last_sect (req->frame_and_sects[i]),
- (long)(sector << SECTOR_SHIFT));
+ size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
+
+ if (req->seg[i].first_sect != 0)
+ DPRINTF("iWR: sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
+ "pos: %15lu\n",
+ req->sector_number, sector,
+ req->seg[i].first_sect, req->seg[i].last_sect,
+ (long)(sector << SECTOR_SHIFT));
spage = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
- spage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
+ spage += req->seg[i].first_sect << SECTOR_SHIFT;
/*convert size and sector to byte offsets */
size <<= SECTOR_SHIFT;
@@ -297,19 +295,17 @@
sector = req->sector_number + (8*i);
- size = blkif_last_sect (req->frame_and_sects[i]) -
- blkif_first_sect(req->frame_and_sects[i]) + 1;
-
+ size = req->seg[i].last_sect - req->seg[i].first_sect + 1;
+
dpage = (char *)MMAP_VADDR(ID_TO_IDX(req->id), i);
- dpage += blkif_first_sect(req->frame_and_sects[i]) << SECTOR_SHIFT;
-
- if (blkif_first_sect(req->frame_and_sects[i]) != 0)
- DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
- "pos: %15lu dpage: %p\n",
- req->sector_number, sector,
- blkif_first_sect(req->frame_and_sects[i]),
- blkif_last_sect (req->frame_and_sects[i]),
- (long)(sector << SECTOR_SHIFT), dpage);
+ dpage += req->seg[i].first_sect << SECTOR_SHIFT;
+
+ if (req->seg[i].first_sect != 0)
+ DPRINTF("iRD : sec_nr: %10llu sec: %10llu (%1lu,%1lu) "
+ "pos: %15lu dpage: %p\n",
+ req->sector_number, sector,
+ req->seg[i].first_sect, req->seg[i].last_sect,
+ (long)(sector << SECTOR_SHIFT), dpage);
/*convert size and sector to byte offsets */
size <<= SECTOR_SHIFT;
diff -r 6a2acc1cc505 -r 28ce48573771 tools/examples/block
--- a/tools/examples/block Wed Nov 30 19:54:28 2005
+++ b/tools/examples/block Wed Nov 30 19:55:08 2005
@@ -89,29 +89,34 @@
fi
done
- for file in /sys/devices/xen-backend/*/physical_device
- do
- if [ -e "$file" ] # Cope with no devices, i.e. the * above did not expand.
- then
- local d=$(cat "$file")
- if [ "$d" == "$devmm" ]
- then
- if [ "$mode" == 'w' ]
- then
- echo 'guest'
- return
- else
- local m=$(cat "${file/physical_device/mode}")
-
- if expr index "$m" 'w' >/dev/null
- then
- echo 'guest'
- return
- fi
- fi
- fi
- fi
- done
+##
+## XXX SMH: the below causes live migration on localhost to fail sometimes
+## since the source domain may still appear to be using a local device.
+## For now simply comment it out - a proper fix will come in due course.
+
+# for file in /sys/devices/xen-backend/*/physical_device
+# do
+# if [ -e "$file" ] # Cope with no devices, i.e. the * above did not
expand.
+# then
+# local d=$(cat "$file")
+# if [ "$d" == "$devmm" ]
+# then
+# if [ "$mode" == 'w' ]
+# then
+# echo 'guest'
+# return
+# else
+# local m=$(cat "${file/physical_device/mode}")
+
+# if expr index "$m" 'w' >/dev/null
+# then
+# echo 'guest'
+# return
+# fi
+# fi
+# fi
+# fi
+# done
echo 'ok'
}
diff -r 6a2acc1cc505 -r 28ce48573771 tools/ioemu/vl.c
--- a/tools/ioemu/vl.c Wed Nov 30 19:54:28 2005
+++ b/tools/ioemu/vl.c Wed Nov 30 19:55:08 2005
@@ -1176,7 +1176,6 @@
int store_console_dev(int domid, char *pts)
{
int xc_handle;
- unsigned int len = 0;
struct xs_handle *xs;
char *path;
@@ -1218,15 +1217,19 @@
#if defined(__linux__)
CharDriverState *qemu_chr_open_pty(void)
{
- char slave_name[1024];
int master_fd, slave_fd;
-
- /* Not satisfying */
- if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
+ struct termios term;
+
+ if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0)
return NULL;
- }
- fprintf(stderr, "char device redirected to %s\n", slave_name);
- store_console_dev(domid, slave_name);
+
+ /* Set raw attributes on the pty. */
+ cfmakeraw(&term);
+ tcsetattr(slave_fd, TCSAFLUSH, &term);
+
+ fprintf(stderr, "char device redirected to %s\n", ptsname(slave_fd));
+ store_console_dev(domid, ptsname(slave_fd));
+
return qemu_chr_open_fd(master_fd, master_fd);
}
#else
diff -r 6a2acc1cc505 -r 28ce48573771 tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c Wed Nov 30 19:54:28 2005
+++ b/tools/libxc/xc_domain.c Wed Nov 30 19:55:08 2005
@@ -365,9 +365,9 @@
int xc_domain_ioport_permission(int xc_handle,
uint32_t domid,
- uint16_t first_port,
- uint16_t nr_ports,
- uint16_t allow_access)
+ uint32_t first_port,
+ uint32_t nr_ports,
+ uint32_t allow_access)
{
DECLARE_DOM0_OP;
diff -r 6a2acc1cc505 -r 28ce48573771 tools/libxc/xc_gnttab.c
--- a/tools/libxc/xc_gnttab.c Wed Nov 30 19:54:28 2005
+++ b/tools/libxc/xc_gnttab.c Wed Nov 30 19:55:08 2005
@@ -42,9 +42,10 @@
int xc_gnttab_map_grant_ref(int xc_handle,
uint64_t host_virt_addr,
uint32_t dom,
- uint16_t ref,
+ grant_ref_t ref,
uint16_t flags,
- int16_t *handle,
+ int16_t *status,
+ grant_handle_t *handle,
uint64_t *dev_bus_addr)
{
struct gnttab_map_grant_ref op;
@@ -58,6 +59,7 @@
if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
&op, 1)) == 0 )
{
+ *status = op.status;
*handle = op.handle;
*dev_bus_addr = op.dev_bus_addr;
}
@@ -69,7 +71,7 @@
int xc_gnttab_unmap_grant_ref(int xc_handle,
uint64_t host_virt_addr,
uint64_t dev_bus_addr,
- uint16_t handle,
+ grant_handle_t handle,
int16_t *status)
{
struct gnttab_unmap_grant_ref op;
diff -r 6a2acc1cc505 -r 28ce48573771 tools/libxc/xenctrl.h
--- a/tools/libxc/xenctrl.h Wed Nov 30 19:54:28 2005
+++ b/tools/libxc/xenctrl.h Wed Nov 30 19:55:08 2005
@@ -13,6 +13,7 @@
#include <sys/ptrace.h>
#include <xen/xen.h>
#include <xen/dom0_ops.h>
+#include <xen/grant_table.h>
#include <xen/version.h>
#include <xen/event_channel.h>
#include <xen/sched.h>
@@ -374,9 +375,9 @@
int xc_domain_ioport_permission(int xc_handle,
uint32_t domid,
- uint16_t first_port,
- uint16_t nr_ports,
- uint16_t allow_access);
+ uint32_t first_port,
+ uint32_t nr_ports,
+ uint32_t allow_access);
unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
unsigned long mfn);
@@ -475,15 +476,16 @@
int xc_gnttab_map_grant_ref(int xc_handle,
uint64_t host_virt_addr,
uint32_t dom,
- uint16_t ref,
+ grant_ref_t ref,
uint16_t flags,
- int16_t *handle,
+ int16_t *status,
+ grant_handle_t *handle,
uint64_t *dev_bus_addr);
int xc_gnttab_unmap_grant_ref(int xc_handle,
uint64_t host_virt_addr,
uint64_t dev_bus_addr,
- uint16_t handle,
+ grant_handle_t handle,
int16_t *status);
int xc_gnttab_setup_table(int xc_handle,
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/crypto/Makefile
--- a/tools/vtpm_manager/crypto/Makefile Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/crypto/Makefile Wed Nov 30 19:55:08 2005
@@ -1,19 +1,19 @@
-XEN_ROOT = ../../..
-include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
-
-BIN = libtcpaCrypto.a
-
-all: build
-
-build: $(BIN)
-
-install: build
-
-clean:
- rm -f *.a *.so *.o *.rpm $(DEP_FILES)
-
-mrproper: clean
- rm -f *~
-
-$(BIN): $(OBJS)
- $(AR) rcs $(BIN) $(OBJS)
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
+
+BIN = libtcpaCrypto.a
+
+all: build
+
+build: $(BIN)
+
+install: build
+
+clean:
+ rm -f *.a *.so *.o *.rpm $(DEP_FILES)
+
+mrproper: clean
+ rm -f *~
+
+$(BIN): $(OBJS)
+ $(AR) rcs $(BIN) $(OBJS)
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/Makefile
--- a/tools/vtpm_manager/manager/Makefile Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/Makefile Wed Nov 30 19:55:08 2005
@@ -1,27 +1,27 @@
-XEN_ROOT = ../../..
-include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
-
-BIN = vtpm_managerd
-
-all: build
-
-build: $(BIN)
-
-install: build
- if [ ! -d "$(DESTDIR)/var/vtpm/fifos" ]; \
- then mkdir -p $(DESTDIR)/var/vtpm/fifos; \
- fi
- $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
-
-clean:
- rm -f *.a *.so *.o *.rpm $(DEP_FILES)
-
-mrproper: clean
- rm -f $(BIN) *~
-
-$(BIN): $(OBJS)
- $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
-
-# libraries
-LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a
-LIBS += -lcrypto -lpthread -lrt -lm
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
+
+BIN = vtpm_managerd
+
+all: build
+
+build: $(BIN)
+
+install: build
+ if [ ! -d "$(DESTDIR)/var/vtpm/fifos" ]; \
+ then mkdir -p $(DESTDIR)/var/vtpm/fifos; \
+ fi
+ $(INSTALL_PROG) $(BIN) $(TOOLS_INSTALL_DIR)
+
+clean:
+ rm -f *.a *.so *.o *.rpm $(DEP_FILES)
+
+mrproper: clean
+ rm -f $(BIN) *~
+
+$(BIN): $(OBJS)
+ $(CC) $(LDFLAGS) $^ $(LIBS) -o $@
+
+# libraries
+LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a
+LIBS += -lcrypto -lpthread -lrt -lm
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/tpmpassthrough.c
--- a/tools/vtpm_manager/manager/tpmpassthrough.c Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/tpmpassthrough.c Wed Nov 30 19:55:08 2005
@@ -1,110 +1,110 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// tpmpassthrough.c
-//
-// Functions regarding passing DMI requests to HWTPM
-//
-// ==================================================================
-
-#include "tcg.h"
-#include "vtpm_manager.h"
-#include "vtpmpriv.h"
-#include "vtsp.h"
-#include "log.h"
-
-TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
- buffer_t *inbuf,
- buffer_t *outbuf) {
-
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE *ord;
-
- ord = (TPM_COMMAND_CODE *) (inbuf->bytes + sizeof(TPM_TAG) + sizeof(UINT32));
-
- switch (*ord) {
-
- // Forbidden for DMI use
- case TPM_ORD_TakeOwnership:
- case TPM_ORD_ChangeAuthOwner:
- case TPM_ORD_DirWriteAuth:
- case TPM_ORD_DirRead:
- case TPM_ORD_AuthorizeMigrationKey:
- case TPM_ORD_CreateMaintenanceArchive:
- case TPM_ORD_LoadMaintenanceArchive:
- case TPM_ORD_KillMaintenanceFeature:
- case TPM_ORD_LoadManuMaintPub:
- case TPM_ORD_ReadManuMaintPub:
- case TPM_ORD_SelfTestFull:
- case TPM_ORD_SelfTestStartup:
- case TPM_ORD_CertifySelfTest:
- case TPM_ORD_ContinueSelfTest:
- case TPM_ORD_GetTestResult:
- case TPM_ORD_Reset:
- case TPM_ORD_OwnerClear:
- case TPM_ORD_DisableOwnerClear:
- case TPM_ORD_ForceClear:
- case TPM_ORD_DisableForceClear:
- case TPM_ORD_GetCapabilityOwner:
- case TPM_ORD_OwnerSetDisable:
- case TPM_ORD_PhysicalEnable:
- case TPM_ORD_PhysicalDisable:
- case TPM_ORD_SetOwnerInstall:
- case TPM_ORD_PhysicalSetDeactivated:
- case TPM_ORD_SetTempDeactivated:
- case TPM_ORD_CreateEndorsementKeyPair:
- case TPM_ORD_GetAuditEvent:
- case TPM_ORD_GetAuditEventSigned:
- case TPM_ORD_GetOrdinalAuditStatus:
- case TPM_ORD_SetOrdinalAuditStatus:
- case TPM_ORD_SetRedirection:
- case TPM_ORD_FieldUpgrade:
- case TSC_ORD_PhysicalPresence:
- status = TPM_DISABLED_CMD;
- goto abort_egress;
- break;
-
- } // End ORD Switch
-
- // Call TCS with command
-
- TPMTRY(TPM_IOERROR, VTSP_RawTransmit( dmi->TCSContext,inbuf, outbuf) );
-
- goto egress;
-
- abort_egress:
- vtpmloginfo(VTPM_LOG_VTPM, "TPM Command Failed in tpmpassthrough.\n");
- egress:
-
- return status;
-}
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// tpmpassthrough.c
+//
+// Functions regarding passing DMI requests to HWTPM
+//
+// ==================================================================
+
+#include "tcg.h"
+#include "vtpm_manager.h"
+#include "vtpmpriv.h"
+#include "vtsp.h"
+#include "log.h"
+
+TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
+ buffer_t *inbuf,
+ buffer_t *outbuf) {
+
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE *ord;
+
+ ord = (TPM_COMMAND_CODE *) (inbuf->bytes + sizeof(TPM_TAG) + sizeof(UINT32));
+
+ switch (*ord) {
+
+ // Forbidden for DMI use
+ case TPM_ORD_TakeOwnership:
+ case TPM_ORD_ChangeAuthOwner:
+ case TPM_ORD_DirWriteAuth:
+ case TPM_ORD_DirRead:
+ case TPM_ORD_AuthorizeMigrationKey:
+ case TPM_ORD_CreateMaintenanceArchive:
+ case TPM_ORD_LoadMaintenanceArchive:
+ case TPM_ORD_KillMaintenanceFeature:
+ case TPM_ORD_LoadManuMaintPub:
+ case TPM_ORD_ReadManuMaintPub:
+ case TPM_ORD_SelfTestFull:
+ case TPM_ORD_SelfTestStartup:
+ case TPM_ORD_CertifySelfTest:
+ case TPM_ORD_ContinueSelfTest:
+ case TPM_ORD_GetTestResult:
+ case TPM_ORD_Reset:
+ case TPM_ORD_OwnerClear:
+ case TPM_ORD_DisableOwnerClear:
+ case TPM_ORD_ForceClear:
+ case TPM_ORD_DisableForceClear:
+ case TPM_ORD_GetCapabilityOwner:
+ case TPM_ORD_OwnerSetDisable:
+ case TPM_ORD_PhysicalEnable:
+ case TPM_ORD_PhysicalDisable:
+ case TPM_ORD_SetOwnerInstall:
+ case TPM_ORD_PhysicalSetDeactivated:
+ case TPM_ORD_SetTempDeactivated:
+ case TPM_ORD_CreateEndorsementKeyPair:
+ case TPM_ORD_GetAuditEvent:
+ case TPM_ORD_GetAuditEventSigned:
+ case TPM_ORD_GetOrdinalAuditStatus:
+ case TPM_ORD_SetOrdinalAuditStatus:
+ case TPM_ORD_SetRedirection:
+ case TPM_ORD_FieldUpgrade:
+ case TSC_ORD_PhysicalPresence:
+ status = TPM_DISABLED_CMD;
+ goto abort_egress;
+ break;
+
+ } // End ORD Switch
+
+ // Call TCS with command
+
+ TPMTRY(TPM_IOERROR, VTSP_RawTransmit( dmi->TCSContext,inbuf, outbuf) );
+
+ goto egress;
+
+ abort_egress:
+ vtpmloginfo(VTPM_LOG_VTPM, "TPM Command Failed in tpmpassthrough.\n");
+ egress:
+
+ return status;
+}
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/vtpm_manager.h
--- a/tools/vtpm_manager/manager/vtpm_manager.h Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/vtpm_manager.h Wed Nov 30 19:55:08 2005
@@ -1,137 +1,137 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// vtpm_manager.h
-//
-// Public Interface header for VTPM Manager
-//
-// ==================================================================
-
-#ifndef __VTPM_MANAGER_H__
-#define __VTPM_MANAGER_H__
-
-#include "tcg.h"
-
-#define VTPM_TAG_REQ 0x01c1
-#define VTPM_TAG_RSP 0x01c4
-#define COMMAND_BUFFER_SIZE 4096
-
-// Header sizes. Note Header MAY include the DMI
-#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) +
sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
-#define VTPM_COMMAND_HEADER_SIZE_CLT ( sizeof(TPM_TAG) +
sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
-
-// ********************** Public Functions *************************
-TPM_RESULT VTPM_Init_Service(); // Start VTPM Service
-void VTPM_Stop_Service(); // Stop VTPM Service
-#ifdef VTPM_MULTI_VM
-int VTPM_Service_Handler();
-#else
-void *VTPM_Service_Handler(void *threadTypePtr);
-#endif
-
-//************************ Command Codes ****************************
-#define VTPM_ORD_OPEN 1 // ULM Creates New DMI
-#define VTPM_ORD_CLOSE 2 // ULM Closes a DMI
-#define VTPM_ORD_DELETE 3 // ULM Permemently Deletes DMI
-#define VTPM_ORD_SAVENVM 4 // DMI requests Secrets Unseal
-#define VTPM_ORD_LOADNVM 5 // DMI requests Secrets Saved
-#define VTPM_ORD_TPMCOMMAND 6 // DMI issues HW TPM Command
-
-//************************ Return Codes ****************************
-#define VTPM_SUCCESS 0
-#define VTPM_FAIL 1
-#define VTPM_UNSUPPORTED 2
-#define VTPM_FORBIDDEN 3
-#define VTPM_RESTORE_CONTEXT_FAILED 4
-#define VTPM_INVALID_REQUEST 5
-
-/******************* Command Parameter API *************************
-
-VTPM Command Format
- dmi: 4 bytes // Source of message.
- // WARNING: This is prepended by the channel.
- // Thus it is received by VTPM Manager,
- // but not sent by DMI
- tpm tag: 2 bytes
- command size: 4 bytes // Size of command including header but not DMI
- ord: 4 bytes // Command ordinal above
- parameters: size - 10 bytes // Command Parameter
-
-VTPM Response Format
- tpm tag: 2 bytes
- response_size: 4 bytes
- status: 4 bytes
- parameters: size - 10 bytes
-
-
-VTPM_Open:
- Input Parameters:
- Domain_type: 1 byte
- domain_id: 4 bytes
- instance_id: 4 bytes
- Output Parameters:
- None
-
-VTPM_Close
- Input Parameters:
- instance_id: 4 bytes
- Output Parameters:
- None
-
-VTPM_Delete
- Input Parameters:
- instance_id: 4 bytes
- Output Parameters:
- None
-
-VTPM_SaveNVM
- Input Parameters:
- data: n bytes (Header indicates size of data)
- Output Parameters:
- None
-
-VTPM_LoadNVM
- Input Parameters:
- None
- Output Parameters:
- data: n bytes (Header indicates size of data)
-
-VTPM_TPMCommand
- Input Parameters:
- TPM Command Byte Stream: n bytes
- Output Parameters:
- TPM Reponse Byte Stream: n bytes
-
-*********************************************************************/
-
-#endif //_VTPM_MANAGER_H_
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// vtpm_manager.h
+//
+// Public Interface header for VTPM Manager
+//
+// ==================================================================
+
+#ifndef __VTPM_MANAGER_H__
+#define __VTPM_MANAGER_H__
+
+#include "tcg.h"
+
+#define VTPM_TAG_REQ 0x01c1
+#define VTPM_TAG_RSP 0x01c4
+#define COMMAND_BUFFER_SIZE 4096
+
+// Header sizes. Note Header MAY include the DMI
+#define VTPM_COMMAND_HEADER_SIZE_SRV ( sizeof(UINT32) + sizeof(TPM_TAG) +
sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
+#define VTPM_COMMAND_HEADER_SIZE_CLT ( sizeof(TPM_TAG) +
sizeof(UINT32) + sizeof(TPM_COMMAND_CODE))
+
+// ********************** Public Functions *************************
+TPM_RESULT VTPM_Init_Service(); // Start VTPM Service
+void VTPM_Stop_Service(); // Stop VTPM Service
+#ifdef VTPM_MULTI_VM
+int VTPM_Service_Handler();
+#else
+void *VTPM_Service_Handler(void *threadTypePtr);
+#endif
+
+//************************ Command Codes ****************************
+#define VTPM_ORD_OPEN 1 // ULM Creates New DMI
+#define VTPM_ORD_CLOSE 2 // ULM Closes a DMI
+#define VTPM_ORD_DELETE 3 // ULM Permemently Deletes DMI
+#define VTPM_ORD_SAVENVM 4 // DMI requests Secrets Unseal
+#define VTPM_ORD_LOADNVM 5 // DMI requests Secrets Saved
+#define VTPM_ORD_TPMCOMMAND 6 // DMI issues HW TPM Command
+
+//************************ Return Codes ****************************
+#define VTPM_SUCCESS 0
+#define VTPM_FAIL 1
+#define VTPM_UNSUPPORTED 2
+#define VTPM_FORBIDDEN 3
+#define VTPM_RESTORE_CONTEXT_FAILED 4
+#define VTPM_INVALID_REQUEST 5
+
+/******************* Command Parameter API *************************
+
+VTPM Command Format
+ dmi: 4 bytes // Source of message.
+ // WARNING: This is prepended by the channel.
+ // Thus it is received by VTPM Manager,
+ // but not sent by DMI
+ tpm tag: 2 bytes
+ command size: 4 bytes // Size of command including header but not DMI
+ ord: 4 bytes // Command ordinal above
+ parameters: size - 10 bytes // Command Parameter
+
+VTPM Response Format
+ tpm tag: 2 bytes
+ response_size: 4 bytes
+ status: 4 bytes
+ parameters: size - 10 bytes
+
+
+VTPM_Open:
+ Input Parameters:
+ Domain_type: 1 byte
+ domain_id: 4 bytes
+ instance_id: 4 bytes
+ Output Parameters:
+ None
+
+VTPM_Close
+ Input Parameters:
+ instance_id: 4 bytes
+ Output Parameters:
+ None
+
+VTPM_Delete
+ Input Parameters:
+ instance_id: 4 bytes
+ Output Parameters:
+ None
+
+VTPM_SaveNVM
+ Input Parameters:
+ data: n bytes (Header indicates size of data)
+ Output Parameters:
+ None
+
+VTPM_LoadNVM
+ Input Parameters:
+ None
+ Output Parameters:
+ data: n bytes (Header indicates size of data)
+
+VTPM_TPMCommand
+ Input Parameters:
+ TPM Command Byte Stream: n bytes
+ Output Parameters:
+ TPM Reponse Byte Stream: n bytes
+
+*********************************************************************/
+
+#endif //_VTPM_MANAGER_H_
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/vtpmd.c
--- a/tools/vtpm_manager/manager/vtpmd.c Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/vtpmd.c Wed Nov 30 19:55:08 2005
@@ -1,134 +1,134 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// vtpmd.c
-//
-// Application
-//
-// ===================================================================
-
-#include <stdio.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include "vtpm_manager.h"
-#include "vtpmpriv.h"
-#include "tcg.h"
-#include "log.h"
-
-#ifndef VTPM_MULTI_VM
- #include <pthread.h>
-#endif
-
-void signal_handler(int reason) {
-#ifndef VTPM_MULTI_VM
-
- if (pthread_equal(pthread_self(), vtpm_globals->master_pid)) {
- if (reason >= 0) { // Reason is a signal
- vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager shutting down for signal
%d.\n", reason);
- } else {// Reason is a TPM_RESULT * -1
- vtpmloginfo(VTPM_LOG_VTPM,"VTPM Manager shuting down for: %s\n",
tpm_get_error_name(-1 * reason) );
- }
-
- return;
- } else {
- vtpmloginfo(VTPM_LOG_VTPM, "Child shutting down\n");
- pthread_exit(NULL);
- }
-#else
- VTPM_Stop_Service();
- exit(-1);
-#endif
-}
-
-struct sigaction ctl_c_handler;
-
-int main(int argc, char **argv) {
-
- vtpmloginfo(VTPM_LOG_VTPM, "Starting VTPM.\n");
-
- if (VTPM_Init_Service() != TPM_SUCCESS) {
- vtpmlogerror(VTPM_LOG_VTPM, "Closing vtpmd due to error during
startup.\n");
- return -1;
- }
-
- ctl_c_handler.sa_handler = signal_handler;
- sigemptyset(&ctl_c_handler.sa_mask);
- ctl_c_handler.sa_flags = 0;
-
- if (sigaction(SIGINT, &ctl_c_handler, NULL) == -1)
- vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGINT handler. Ctl+break
will not stop service gently.\n");
-
- // For easier debuggin with gdb
- if (sigaction(SIGHUP, &ctl_c_handler, NULL) == -1)
- vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGHUP handler. Ctl+break
will not stop service gently.\n");
-
-#ifdef VTPM_MULTI_VM
- TPM_RESULT status = VTPM_Service_Handler();
-
- if (status != TPM_SUCCESS)
- vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager exited with status %s. It never
should exit.\n", tpm_get_error_name(status));
-
- return -1;
-#else
- sigset_t sig_mask;
-
- sigemptyset(&sig_mask);
- sigaddset(&sig_mask, SIGPIPE);
- sigprocmask(SIG_BLOCK, &sig_mask, NULL);
- //pthread_mutex_init(&vtpm_globals->dmi_mutex, NULL);
- pthread_t be_thread, dmi_thread;
- int betype_be, dmitype_dmi;
-
- vtpm_globals->master_pid = pthread_self();
-
- betype_be = BE_LISTENER_THREAD;
- if (pthread_create(&be_thread, NULL, VTPM_Service_Handler, &betype_be) != 0)
{
- vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n");
- exit(-1);
- }
-
- dmitype_dmi = DMI_LISTENER_THREAD;
- if (pthread_create(&dmi_thread, NULL, VTPM_Service_Handler, &dmitype_dmi) !=
0) {
- vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch DMI Thread.\n");
- exit(-1);
- }
-
- //Join the other threads until exit time.
- pthread_join(be_thread, NULL);
- pthread_join(dmi_thread, NULL);
-
- VTPM_Stop_Service();
- return 0;
-#endif
-}
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// vtpmd.c
+//
+// Application
+//
+// ===================================================================
+
+#include <stdio.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "vtpm_manager.h"
+#include "vtpmpriv.h"
+#include "tcg.h"
+#include "log.h"
+
+#ifndef VTPM_MULTI_VM
+ #include <pthread.h>
+#endif
+
+void signal_handler(int reason) {
+#ifndef VTPM_MULTI_VM
+
+ if (pthread_equal(pthread_self(), vtpm_globals->master_pid)) {
+ if (reason >= 0) { // Reason is a signal
+ vtpmloginfo(VTPM_LOG_VTPM, "VTPM Manager shutting down for signal
%d.\n", reason);
+ } else {// Reason is a TPM_RESULT * -1
+ vtpmloginfo(VTPM_LOG_VTPM,"VTPM Manager shuting down for: %s\n",
tpm_get_error_name(-1 * reason) );
+ }
+
+ return;
+ } else {
+ vtpmloginfo(VTPM_LOG_VTPM, "Child shutting down\n");
+ pthread_exit(NULL);
+ }
+#else
+ VTPM_Stop_Service();
+ exit(-1);
+#endif
+}
+
+struct sigaction ctl_c_handler;
+
+int main(int argc, char **argv) {
+
+ vtpmloginfo(VTPM_LOG_VTPM, "Starting VTPM.\n");
+
+ if (VTPM_Init_Service() != TPM_SUCCESS) {
+ vtpmlogerror(VTPM_LOG_VTPM, "Closing vtpmd due to error during
startup.\n");
+ return -1;
+ }
+
+ ctl_c_handler.sa_handler = signal_handler;
+ sigemptyset(&ctl_c_handler.sa_mask);
+ ctl_c_handler.sa_flags = 0;
+
+ if (sigaction(SIGINT, &ctl_c_handler, NULL) == -1)
+ vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGINT handler. Ctl+break
will not stop service gently.\n");
+
+ // For easier debuggin with gdb
+ if (sigaction(SIGHUP, &ctl_c_handler, NULL) == -1)
+ vtpmlogerror(VTPM_LOG_VTPM, "Could not install SIGHUP handler. Ctl+break
will not stop service gently.\n");
+
+#ifdef VTPM_MULTI_VM
+ TPM_RESULT status = VTPM_Service_Handler();
+
+ if (status != TPM_SUCCESS)
+ vtpmlogerror(VTPM_LOG_VTPM, "VTPM Manager exited with status %s. It never
should exit.\n", tpm_get_error_name(status));
+
+ return -1;
+#else
+ sigset_t sig_mask;
+
+ sigemptyset(&sig_mask);
+ sigaddset(&sig_mask, SIGPIPE);
+ sigprocmask(SIG_BLOCK, &sig_mask, NULL);
+ //pthread_mutex_init(&vtpm_globals->dmi_mutex, NULL);
+ pthread_t be_thread, dmi_thread;
+ int betype_be, dmitype_dmi;
+
+ vtpm_globals->master_pid = pthread_self();
+
+ betype_be = BE_LISTENER_THREAD;
+ if (pthread_create(&be_thread, NULL, VTPM_Service_Handler, &betype_be) != 0)
{
+ vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch BE Thread.\n");
+ exit(-1);
+ }
+
+ dmitype_dmi = DMI_LISTENER_THREAD;
+ if (pthread_create(&dmi_thread, NULL, VTPM_Service_Handler, &dmitype_dmi) !=
0) {
+ vtpmlogerror(VTPM_LOG_VTPM, "Failed to launch DMI Thread.\n");
+ exit(-1);
+ }
+
+ //Join the other threads until exit time.
+ pthread_join(be_thread, NULL);
+ pthread_join(dmi_thread, NULL);
+
+ VTPM_Stop_Service();
+ return 0;
+#endif
+}
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/vtpmpriv.h
--- a/tools/vtpm_manager/manager/vtpmpriv.h Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/vtpmpriv.h Wed Nov 30 19:55:08 2005
@@ -1,151 +1,151 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// vtpmpriv.h
-//
-// Structures and functions private to the manager
-//
-// ==================================================================
-
-#ifndef __VTPMPRIV_H__
-#define __VTPMPRIV_H__
-
-#include "tcg.h"
-#include "tcs.h"
-#include "buffer.h"
-#include "crypto.h"
-
-#define STATE_FILE "/var/vtpm/VTPM"
-#define DMI_NVM_FILE "/var/vtpm/vtpm_dm_%d.data"
-#define VTPM_BE_DEV "/dev/vtpm0"
-#define VTPM_CTL_DM 0
-
-#ifndef VTPM_MUTLI_VM
- #include <sys/types.h>
- #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-to-%d.fifo"
- #define GUEST_RX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
-
- #define VTPM_TX_FIFO "/var/vtpm/fifos/vtpm-to-%d.fifo"
- #define VTPM_RX_FIFO "/var/vtpm/fifos/vtpm-from-all.fifo"
-
- #define BE_LISTENER_THREAD 1
- #define DMI_LISTENER_THREAD 2
-
- // Seconds until DMI timeout. Timeouts result in DMI being out
- // of sync, which may require a reboot of DMI and guest to recover
- // from. Don't set this to low. Also note that DMI may issue a TPM
- // call so we should expect time to process at DMI + TPM processing.
- #define DMI_TIMEOUT 90
-#endif
-
-
-// ------------------------ Private Structures -----------------------
-typedef struct VTPM_DMI_RESOURCE_T {
- // I/O info for Manager to talk to DMI's over FIFOs
-#ifndef VTPM_MUTLI_VM
- int guest_tx_fh; // open GUEST_TX_FIFO
- int vtpm_tx_fh; // open VTPM_TX_FIFO
- char *guest_tx_fname; // open GUEST_TX_FIFO
- char *vtpm_tx_fname; // open VTPM_TX_FIFO
-
- pid_t dmi_pid;
-#endif
- // Non-persistent Information
- bool connected;
- UINT32 dmi_domain_id;
- TCS_CONTEXT_HANDLE TCSContext; // TCS Handle
- char *NVMLocation; // NULL term string indicating location
- // of NVM.
- // Persistent Information about DMI
- UINT32 dmi_id;
- TPM_DIGEST NVM_measurement; // Equal to the SHA1 of the blob
- TPM_DIGEST DMI_measurement; // Correct measurement of the owning
DMI
-} VTPM_DMI_RESOURCE;
-
-typedef struct tdVTPM_GLOBALS {
- // Non-persistent data
- int be_fh; // File handle to ipc used to
communicate with backend
-#ifndef VTPM_MULTI_VM
- int vtpm_rx_fh;
- int guest_rx_fh;
-
- pid_t master_pid;
-#endif
- struct hashtable *dmi_map; // Table of all DMI's known
indexed by persistent instance #
-#ifndef VTPM_MULTI_VM
- pthread_mutex_t dmi_map_mutex; //
-#endif
- TCS_CONTEXT_HANDLE manager_tcs_handle; // TCS Handle used by manager
- TPM_HANDLE storageKeyHandle; // Key used by persistent store
- CRYPTO_INFO storageKey; // For software encryption
- TCS_AUTH keyAuth; // OIAP session for storageKey
- BOOL DMI_table_dirty; // Indicates that a command
- // has updated the DMI table
-
-
- // Persistent Data
- TPM_AUTHDATA owner_usage_auth; // OwnerAuth of real TPM
- TPM_AUTHDATA srk_usage_auth; // SRK Auth of real TPM
- buffer_t storageKeyWrap; // Wrapped copy of storageKey
-
- TPM_AUTHDATA storage_key_usage_auth;
-
-}VTPM_GLOBALS;
-
-//Global dmi map
-extern VTPM_GLOBALS *vtpm_globals;
-
-// ********************** Command Handler Prototypes ***********************
-TPM_RESULT VTPM_Handle_Load_NVM( VTPM_DMI_RESOURCE *myDMI,
- const buffer_t *inbuf,
- buffer_t *outbuf);
-
-TPM_RESULT VTPM_Handle_Save_NVM( VTPM_DMI_RESOURCE *myDMI,
- const buffer_t *inbuf,
- buffer_t *outbuf);
-
-TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
- buffer_t *inbuf,
- buffer_t *outbuf);
-
-TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf);
-
-TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf);
-
-TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf);
-
-TPM_RESULT VTPM_SaveService(void);
-TPM_RESULT VTPM_LoadService(void);
-
-TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res);
-#endif // __VTPMPRIV_H__
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// vtpmpriv.h
+//
+// Structures and functions private to the manager
+//
+// ==================================================================
+
+#ifndef __VTPMPRIV_H__
+#define __VTPMPRIV_H__
+
+#include "tcg.h"
+#include "tcs.h"
+#include "buffer.h"
+#include "crypto.h"
+
+#define STATE_FILE "/var/vtpm/VTPM"
+#define DMI_NVM_FILE "/var/vtpm/vtpm_dm_%d.data"
+#define VTPM_BE_DEV "/dev/vtpm0"
+#define VTPM_CTL_DM 0
+
+#ifndef VTPM_MUTLI_VM
+ #include <sys/types.h>
+ #define GUEST_TX_FIFO "/var/vtpm/fifos/guest-to-%d.fifo"
+ #define GUEST_RX_FIFO "/var/vtpm/fifos/guest-from-all.fifo"
+
+ #define VTPM_TX_FIFO "/var/vtpm/fifos/vtpm-to-%d.fifo"
+ #define VTPM_RX_FIFO "/var/vtpm/fifos/vtpm-from-all.fifo"
+
+ #define BE_LISTENER_THREAD 1
+ #define DMI_LISTENER_THREAD 2
+
+ // Seconds until DMI timeout. Timeouts result in DMI being out
+ // of sync, which may require a reboot of DMI and guest to recover
+ // from. Don't set this to low. Also note that DMI may issue a TPM
+ // call so we should expect time to process at DMI + TPM processing.
+ #define DMI_TIMEOUT 90
+#endif
+
+
+// ------------------------ Private Structures -----------------------
+typedef struct VTPM_DMI_RESOURCE_T {
+ // I/O info for Manager to talk to DMI's over FIFOs
+#ifndef VTPM_MUTLI_VM
+ int guest_tx_fh; // open GUEST_TX_FIFO
+ int vtpm_tx_fh; // open VTPM_TX_FIFO
+ char *guest_tx_fname; // open GUEST_TX_FIFO
+ char *vtpm_tx_fname; // open VTPM_TX_FIFO
+
+ pid_t dmi_pid;
+#endif
+ // Non-persistent Information
+ bool connected;
+ UINT32 dmi_domain_id;
+ TCS_CONTEXT_HANDLE TCSContext; // TCS Handle
+ char *NVMLocation; // NULL term string indicating location
+ // of NVM.
+ // Persistent Information about DMI
+ UINT32 dmi_id;
+ TPM_DIGEST NVM_measurement; // Equal to the SHA1 of the blob
+ TPM_DIGEST DMI_measurement; // Correct measurement of the owning
DMI
+} VTPM_DMI_RESOURCE;
+
+typedef struct tdVTPM_GLOBALS {
+ // Non-persistent data
+ int be_fh; // File handle to ipc used to
communicate with backend
+#ifndef VTPM_MULTI_VM
+ int vtpm_rx_fh;
+ int guest_rx_fh;
+
+ pid_t master_pid;
+#endif
+ struct hashtable *dmi_map; // Table of all DMI's known
indexed by persistent instance #
+#ifndef VTPM_MULTI_VM
+ pthread_mutex_t dmi_map_mutex; //
+#endif
+ TCS_CONTEXT_HANDLE manager_tcs_handle; // TCS Handle used by manager
+ TPM_HANDLE storageKeyHandle; // Key used by persistent store
+ CRYPTO_INFO storageKey; // For software encryption
+ TCS_AUTH keyAuth; // OIAP session for storageKey
+ BOOL DMI_table_dirty; // Indicates that a command
+ // has updated the DMI table
+
+
+ // Persistent Data
+ TPM_AUTHDATA owner_usage_auth; // OwnerAuth of real TPM
+ TPM_AUTHDATA srk_usage_auth; // SRK Auth of real TPM
+ buffer_t storageKeyWrap; // Wrapped copy of storageKey
+
+ TPM_AUTHDATA storage_key_usage_auth;
+
+}VTPM_GLOBALS;
+
+//Global dmi map
+extern VTPM_GLOBALS *vtpm_globals;
+
+// ********************** Command Handler Prototypes ***********************
+TPM_RESULT VTPM_Handle_Load_NVM( VTPM_DMI_RESOURCE *myDMI,
+ const buffer_t *inbuf,
+ buffer_t *outbuf);
+
+TPM_RESULT VTPM_Handle_Save_NVM( VTPM_DMI_RESOURCE *myDMI,
+ const buffer_t *inbuf,
+ buffer_t *outbuf);
+
+TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
+ buffer_t *inbuf,
+ buffer_t *outbuf);
+
+TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf);
+
+TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf);
+
+TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf);
+
+TPM_RESULT VTPM_SaveService(void);
+TPM_RESULT VTPM_LoadService(void);
+
+TPM_RESULT close_dmi( VTPM_DMI_RESOURCE *dmi_res);
+#endif // __VTPMPRIV_H__
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/vtsp.c
--- a/tools/vtpm_manager/manager/vtsp.c Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/vtsp.c Wed Nov 30 19:55:08 2005
@@ -1,810 +1,810 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// vtsp.c
-//
-// Higher level interface to TCS for use in service.
-//
-// ==================================================================
-
-#include <string.h>
-#include "tcg.h"
-#include "tcs.h"
-#include "bsg.h"
-#include "log.h"
-#include "crypto.h"
-#include "vtsp.h"
-#include "buffer.h"
-
-#define RSA_KEY_SIZE 0x0800
-
-/***********************************************************************************
- * GenerateAuth: Generate authorization info to be sent back to application
- *
- * Parameters: outParamDigestText The concatenation of output parameters to
be SHA1ed
- * outParamDigestTextSize Size of inParamDigestText
- * HMACkey Key to be used for HMACing
- * For OIAP use key.authUsage or PersistStore.ownerAuth
- * For OSAP use shared secret
- * pAuth Authorization information from the application
- *
- * Return: TPM_SUCCESS Authorization data created
- * TPM_AUTHFAIL Invalid (NULL) HMACkey presented for OSAP
-
*************************************************************************************/
-TPM_RESULT GenerateAuth( /*[IN]*/ const BYTE *inParamDigestText,
- /*[IN]*/ UINT32 inParamDigestTextSize,
- /*[IN]*/ const TPM_SECRET *HMACkey,
- /*[IN,OUT]*/ TCS_AUTH *auth) {
-
- if (inParamDigestText == NULL || auth == NULL)
- return (TPM_AUTHFAIL);
- else {
-
- //Generate new OddNonce
- Crypto_GetRandom(auth->NonceOdd.nonce, sizeof(TPM_NONCE));
-
- // Create SHA1 inParamDigest
- TPM_DIGEST inParamDigest;
- Crypto_SHA1Full(inParamDigestText, inParamDigestTextSize, (BYTE *)
&inParamDigest);
-
- // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
- BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
-
- BSG_PackList( hmacText, 4,
- BSG_TPM_DIGEST, &inParamDigest,
- BSG_TPM_NONCE, &(auth->NonceEven),
- BSG_TPM_NONCE, &(auth->NonceOdd),
- BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
-
- Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText), (BYTE *) HMACkey,
sizeof(TPM_DIGEST), (BYTE *) &(auth->HMAC));
-
- return(TPM_SUCCESS);
-
- }
-}
-
-/***********************************************************************************
- * VerifyAuth: Verify the authdata for a command requiring authorization
- *
- * Parameters: inParamDigestText The concatenation of parameters to be SHA1ed
- * inParamDigestTextSize Size of inParamDigestText
- * authDataUsage AuthDataUsage for the Entity being used
- * Key->authDataUsage or TPM_AUTH_OWNER
- * HMACkey Key to be used for HMACing
- * For OIAP use key.authUsage or PersistStore.ownerAuth
- * For OSAP use NULL (It will be aquired from the Auth Session)
- * If unknown (default), assume OIAP
- * sessionAuth A TCS_AUTH info for the session
- * pAuth Authorization information from the application
- * hContext If specified, on failed Auth, VerifyAuth will
- * generate a new OIAP session in place
of themselves
- * destroyed session.
- *
- * Return: TPM_SUCCESS Authorization Verified
- * TPM_AUTHFAIL Authorization Failed
- * TPM_FAIL Failure during SHA1 routines
-
*************************************************************************************/
-TPM_RESULT VerifyAuth( /*[IN]*/ const BYTE *outParamDigestText,
- /*[IN]*/ UINT32 outParamDigestTextSize,
- /*[IN]*/ const TPM_SECRET *HMACkey,
- /*[IN,OUT]*/ TCS_AUTH *auth,
- /*[IN]*/ TCS_CONTEXT_HANDLE hContext) {
- if (outParamDigestText == NULL || auth == NULL)
- return (TPM_AUTHFAIL);
-
-
- // Create SHA1 inParamDigest
- TPM_DIGEST outParamDigest;
- Crypto_SHA1Full(outParamDigestText, outParamDigestTextSize, (BYTE *)
&outParamDigest);
-
- // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
- TPM_DIGEST hm;
- BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
-
- BSG_PackList( hmacText, 4,
- BSG_TPM_DIGEST, &outParamDigest,
- BSG_TPM_NONCE, &(auth->NonceEven),
- BSG_TPM_NONCE, &(auth->NonceOdd),
- BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
-
- Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText),
- (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &hm);
-
- // Compare correct HMAC with provided one.
- if (memcmp (&hm, &(auth->HMAC), sizeof(TPM_DIGEST)) == 0) // 0 indicates
equality
- return (TPM_SUCCESS);
- else {
- VTSP_OIAP( hContext, auth);
- return (TPM_AUTHFAIL);
- }
-}
-
-TPM_RESULT VTSP_OIAP(const TCS_CONTEXT_HANDLE hContext,
- TCS_AUTH *auth) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "OIAP.\n");
- TPM_RESULT status = TPM_SUCCESS;
- TPMTRYRETURN( TCSP_OIAP(hContext,
- &auth->AuthHandle,
- &auth->NonceEven) );
- goto egress;
-
- abort_egress:
-
- egress:
-
- return status;
-}
-
-TPM_RESULT VTSP_OSAP(const TCS_CONTEXT_HANDLE hContext,
- const TPM_ENTITY_TYPE entityType,
- const UINT32 entityValue,
- const TPM_AUTHDATA *usageAuth,
- TPM_SECRET *sharedSecret,
- TCS_AUTH *auth) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "OSAP.\n");
- TPM_RESULT status = TPM_SUCCESS;
- TPM_NONCE nonceEvenOSAP, nonceOddOSAP;
-
- Crypto_GetRandom((BYTE *) &nonceOddOSAP, sizeof(TPM_NONCE) );
-
- TPMTRYRETURN( TCSP_OSAP( hContext,
- entityType,
- entityValue,
- nonceOddOSAP,
- &auth->AuthHandle,
- &auth->NonceEven,
- &nonceEvenOSAP) );
-
- // Calculating Session Secret
- BYTE sharedSecretText[TPM_DIGEST_SIZE * 2];
-
- BSG_PackList( sharedSecretText, 2,
- BSG_TPM_NONCE, &nonceEvenOSAP,
- BSG_TPM_NONCE, &nonceOddOSAP);
-
- Crypto_HMAC(sharedSecretText, sizeof(sharedSecretText), (BYTE *) usageAuth,
TPM_DIGEST_SIZE, (BYTE *) sharedSecret);
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- return status;
-}
-
-
-
-TPM_RESULT VTSP_ReadPubek( const TCS_CONTEXT_HANDLE hContext,
- CRYPTO_INFO *crypto_info) {
-
- TPM_RESULT status;
- TPM_NONCE antiReplay;
- TPM_DIGEST checksum;
- BYTE *pubEKtext;
- UINT32 pubEKtextsize;
-
- vtpmloginfo(VTPM_LOG_VTSP, "Reading Public EK.\n");
-
- // GenerateAuth new nonceOdd
- Crypto_GetRandom(&antiReplay, sizeof(TPM_NONCE) );
-
-
- TPMTRYRETURN( TCSP_ReadPubek( hContext,
- antiReplay,
- &pubEKtextsize,
- &pubEKtext,
- &checksum) );
-
-
- // Extract the remaining output parameters
- TPM_PUBKEY pubEK;
-
- BSG_Unpack(BSG_TPM_PUBKEY, pubEKtext, (BYTE *) &pubEK);
-
- // Build CryptoInfo for the bindingKey
- TPM_RSA_KEY_PARMS rsaKeyParms;
-
- BSG_Unpack(BSG_TPM_RSA_KEY_PARMS,
- pubEK.algorithmParms.parms,
- &rsaKeyParms);
-
- Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize,
- rsaKeyParms.exponent,
- pubEK.pubKey.keyLength,
- pubEK.pubKey.key,
- crypto_info);
-
- // Destroy rsaKeyParms
- BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
-
- // Set encryption scheme
- crypto_info->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
- //crypto_info->encScheme = pubEK.algorithmParms.encScheme;
- crypto_info->algorithmID = pubEK.algorithmParms.algorithmID;
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- return status;
-}
-
-TPM_RESULT VTSP_TakeOwnership( const TCS_CONTEXT_HANDLE hContext,
- const TPM_AUTHDATA *ownerAuth,
- const TPM_AUTHDATA *srkAuth,
- CRYPTO_INFO *ek_cryptoInfo,
- TCS_AUTH *auth) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "Taking Ownership of TPM.\n");
-
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE command = TPM_ORD_TakeOwnership;
- TPM_PROTOCOL_ID proto_id = TPM_PID_OWNER;
- BYTE *new_srk;
-
- BYTE *paramText; // Digest to make Auth.
- UINT32 paramTextSize;
-
- // vars for srkpubkey parameter
- TPM_KEY srkPub;
- TPM_KEY_PARMS srkKeyInfo = {TPM_ALG_RSA, TPM_ES_RSAESOAEP_SHA1_MGF1,
TPM_SS_NONE, 12, 0};
- BYTE srkRSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00};
- srkKeyInfo.parms = (BYTE *) &srkRSAkeyInfo;
-
- struct pack_buf_t srkText;
-
- // GenerateAuth new nonceOdd
- Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
-
- //These values are accurate for an enc(AuthData).
- struct pack_buf_t encOwnerAuth, encSrkAuth;
-
- encOwnerAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
- encSrkAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
-
- if (encOwnerAuth.data == NULL || encSrkAuth.data == NULL) {
- vtpmloginfo(VTPM_LOG_VTSP, "Could not malloc encrypted auths.\n");
- status = TPM_RESOURCES;
- goto abort_egress;
- }
-
- Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) ownerAuth,
&encOwnerAuth.size, encOwnerAuth.data);
- Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) srkAuth,
&encSrkAuth.size, encSrkAuth.data);
-
-
- // Build srk public key struct
- srkPub.ver = TPM_STRUCT_VER_1_1;
- srkPub.keyUsage = TPM_KEY_STORAGE;
- srkPub.keyFlags = 0x00;
- srkPub.authDataUsage = TPM_AUTH_ALWAYS;
- memcpy(&srkPub.algorithmParms, &srkKeyInfo, sizeof(TPM_KEY_PARMS));
- srkPub.PCRInfoSize = 0;
- srkPub.PCRInfo = 0;
- srkPub.pubKey.keyLength= 0;
- srkPub.encDataSize = 0;
-
- srkText.data = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
- srkText.size = BSG_Pack(BSG_TPM_KEY, (BYTE *) &srkPub, srkText.data);
-
- paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
-
- paramTextSize = BSG_PackList(paramText, 5,
- BSG_TPM_COMMAND_CODE,&command,
- BSG_TPM_PROTOCOL_ID, &proto_id,
- BSG_TPM_SIZE32_DATA, &encOwnerAuth,
- BSG_TPM_SIZE32_DATA, &encSrkAuth,
- BSG_TPM_KEY, &srkPub);
-
- TPMTRYRETURN( GenerateAuth( paramText, paramTextSize, ownerAuth, auth) );
-
- new_srk = srkText.data;
- TPMTRYRETURN( TCSP_TakeOwnership ( hContext,
- proto_id,
- encOwnerAuth.size,
- encOwnerAuth.data,
- encSrkAuth.size,
- encSrkAuth.data,
- &srkText.size,
- &new_srk,
- auth ) );
-
-
- paramTextSize = BSG_PackList(paramText, 2,
- BSG_TPM_RESULT, &status,
- BSG_TPM_COMMAND_CODE, &command);
- memcpy(paramText + paramTextSize, new_srk, srkText.size);
- paramTextSize += srkText.size;
-
-
- TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
- ownerAuth, auth,
- hContext) );
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- free(srkText.data);
- free(encSrkAuth.data);
- free(encOwnerAuth.data);
- free(paramText);
-
- TCS_FreeMemory(hContext, new_srk);
-
- return status;
-}
-
-TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE hContext,
- const TPM_AUTHDATA *ownerAuth,
- TCS_AUTH *auth) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "Disabling Pubek Read.\n");
-
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE command = TPM_ORD_DisablePubekRead;
-
- BYTE *paramText; // Digest to make Auth.
- UINT32 paramTextSize;
-
- // Generate HMAC
- Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
-
- paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
-
- paramTextSize = BSG_PackList(paramText, 1,
- BSG_TPM_COMMAND_CODE, &command);
-
- TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
- ownerAuth, auth) );
-
- // Call TCS
- TPMTRYRETURN( TCSP_DisablePubekRead ( hContext, // in
- auth) );
-
- // Verify Auth
- paramTextSize = BSG_PackList(paramText, 2,
- BSG_TPM_RESULT, &status,
- BSG_TPM_COMMAND_CODE, &command);
-
- TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
- ownerAuth, auth,
- hContext) );
- goto egress;
-
- abort_egress:
- egress:
- free(paramText);
- return status;
-}
-
-TPM_RESULT VTSP_CreateWrapKey( const TCS_CONTEXT_HANDLE hContext,
- const TPM_KEY_USAGE usage,
- const TPM_AUTHDATA *newKeyAuth,
- const TCS_KEY_HANDLE parentHandle,
- const TPM_AUTHDATA *osapSharedSecret,
- buffer_t *pubKeyBuf,
- TCS_AUTH *auth) {
-
- int i;
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE command = TPM_ORD_CreateWrapKey;
-
- vtpmloginfo(VTPM_LOG_VTSP, "Creating new key of type %d.\n", usage);
-
- // vars for Calculate encUsageAuth
- BYTE *paramText;
- UINT32 paramTextSize;
-
- // vars for Calculate encUsageAuth
- BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
- TPM_DIGEST XORKey1;
- UINT32 XORbufferSize;
- TPM_SECRET encUsageAuth, encMigrationAuth;
-
- // vars for Flatten newKey prototype
- BYTE *flatKey = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
- UINT32 flatKeySize = TCPA_MAX_BUFFER_LENGTH;
- struct pack_buf_t newKeyText;
-
- // Fill in newKey
- TPM_KEY newKey;
-
- BYTE RSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00};
- newKey.algorithmParms.algorithmID = TPM_ALG_RSA;
- newKey.algorithmParms.parms = (BYTE *) &RSAkeyInfo;
- newKey.algorithmParms.parmSize = 12;
-
- switch (usage) {
- case TPM_KEY_SIGNING:
- vtpmloginfo(VTPM_LOG_VTSP, "Creating Signing Key...\n");
- newKey.keyUsage = TPM_KEY_SIGNING;
- newKey.algorithmParms.encScheme = TPM_ES_NONE;
- newKey.algorithmParms.sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1;
- break;
- case TPM_KEY_STORAGE:
- vtpmloginfo(VTPM_LOG_VTSP, "Creating Storage Key...\n");
- newKey.keyUsage = TPM_KEY_STORAGE;
- newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
- newKey.algorithmParms.sigScheme = TPM_SS_NONE;
- break;
- case TPM_KEY_BIND:
- vtpmloginfo(VTPM_LOG_VTSP, "Creating Binding Key...\n");
- newKey.keyUsage = TPM_KEY_BIND;
- newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
- newKey.algorithmParms.sigScheme = TPM_SS_NONE;
- break;
- default:
- vtpmloginfo(VTPM_LOG_VTSP, "Cannot create key. Invalid Key Type.\n");
- status = TPM_BAD_PARAMETER;
- goto abort_egress;
- }
-
-
- newKey.ver = TPM_STRUCT_VER_1_1;
-
- newKey.keyFlags = 0;
- newKey.authDataUsage = TPM_AUTH_ALWAYS;
- newKey.pubKey.keyLength= 0;
- newKey.encDataSize = 0;
- newKey.encData = NULL;
-
- // FIXME: Support PCR bindings
- newKey.PCRInfoSize = 0;
- newKey.PCRInfo = NULL;
-
- // Calculate encUsageAuth
- XORbufferSize = BSG_PackList( XORbuffer, 2,
- BSG_TPM_SECRET, osapSharedSecret,
- BSG_TPM_NONCE, &auth->NonceEven);
- Crypto_SHA1Full(XORbuffer, XORbufferSize, (BYTE *) &XORKey1);
-
- // FIXME: No support for migratable keys.
- for (i=0; i < TPM_DIGEST_SIZE; i++)
- ((BYTE *) &encUsageAuth)[i] = ((BYTE *) &XORKey1)[i] ^ ((BYTE *)
newKeyAuth)[i];
-
- // Flatten newKey prototype
- flatKeySize = BSG_Pack(BSG_TPM_KEY, (BYTE *) &newKey, flatKey);
- newKeyText.data = flatKey;
- newKeyText.size = flatKeySize;
-
- // GenerateAuth new nonceOdd
- Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
-
- // Generate HMAC
- paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
-
- paramTextSize = BSG_PackList(paramText, 3,
- BSG_TPM_COMMAND_CODE, &command,
- BSG_TPM_AUTHDATA, &encUsageAuth,
- BSG_TPM_AUTHDATA, &encMigrationAuth);
- memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
- paramTextSize += newKeyText.size;
-
-
- TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
- osapSharedSecret, auth) );
-
- // Call TCS
- TPMTRYRETURN( TCSP_CreateWrapKey( hContext,
- parentHandle,
- encUsageAuth,
- encMigrationAuth,
- &newKeyText.size,
- &newKeyText.data,
- auth) );
-
- // Verify Auth
- paramTextSize = BSG_PackList(paramText, 2,
- BSG_TPM_RESULT, &status,
- BSG_TPM_COMMAND_CODE, &command);
- memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
- paramTextSize += newKeyText.size;
-
- TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
- osapSharedSecret, auth, 0) );
-
- // Unpack/return key structure
- TPMTRYRETURN(buffer_init(pubKeyBuf, 0, 0) );
- TPMTRYRETURN(buffer_append_raw(pubKeyBuf, newKeyText.size, newKeyText.data)
);
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- free(flatKey);
- free(paramText);
- TCS_FreeMemory(hContext, newKeyText.data);
-
- return status;
-}
-
-TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE hContext,
- const TCS_KEY_HANDLE hUnwrappingKey,
- const buffer_t *rgbWrappedKeyBlob,
- const TPM_AUTHDATA *parentAuth,
- TPM_HANDLE *newKeyHandle,
- TCS_AUTH *auth,
- CRYPTO_INFO *cryptoinfo /*= NULL*/) {
-
-
- vtpmloginfo(VTPM_LOG_VTSP, "Loading Key.\n%s","");
-
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE command = TPM_ORD_LoadKey;
-
- BYTE *paramText; // Digest to make Auth.
- UINT32 paramTextSize;
-
- if ((rgbWrappedKeyBlob == NULL) || (parentAuth == NULL) ||
- (newKeyHandle==NULL) || (auth==NULL)) {
- status = TPM_BAD_PARAMETER;
- goto abort_egress;
- }
-
- // Generate Extra TCS Parameters
- TPM_HANDLE phKeyHMAC;
-
- // Generate HMAC
- Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
-
- paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
-
- paramTextSize = BSG_PackList(paramText, 1,
- BSG_TPM_COMMAND_CODE, &command);
-
- memcpy(paramText + paramTextSize, rgbWrappedKeyBlob->bytes,
buffer_len(rgbWrappedKeyBlob));
- paramTextSize += buffer_len(rgbWrappedKeyBlob);
-
- TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
- parentAuth, auth) );
-
- // Call TCS
- TPMTRYRETURN( TCSP_LoadKeyByBlob( hContext,
- hUnwrappingKey,
- buffer_len(rgbWrappedKeyBlob),
- rgbWrappedKeyBlob->bytes,
- auth,
- newKeyHandle,
- &phKeyHMAC) );
-
- // Verify Auth
- paramTextSize = BSG_PackList(paramText, 3,
- BSG_TPM_RESULT, &status,
- BSG_TPM_COMMAND_CODE, &command,
- BSG_TPM_HANDLE, newKeyHandle);
-
- TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
- parentAuth, auth,
- hContext) );
-
- // Unpack/return key structure
- if (cryptoinfo != NULL) {
- TPM_KEY newKey;
-
- BSG_Unpack(BSG_TPM_KEY, rgbWrappedKeyBlob->bytes , &newKey);
- TPM_RSA_KEY_PARMS rsaKeyParms;
-
- BSG_Unpack(BSG_TPM_RSA_KEY_PARMS,
- newKey.algorithmParms.parms,
- &rsaKeyParms);
-
- Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize,
- rsaKeyParms.exponent,
- newKey.pubKey.keyLength,
- newKey.pubKey.key,
- cryptoinfo);
-
- // Destroy rsaKeyParms
- BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
-
- // Set encryption scheme
- cryptoinfo->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
- }
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- free(paramText);
- return status;
-}
-
-TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE hContext,
- const TPM_KEY_HANDLE key_handle,
- const buffer_t *bound_data,
- const TPM_AUTHDATA *usage_auth,
- buffer_t *clear_data,
- TCS_AUTH *auth) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "Unbinding %d bytes of data.\n",
buffer_len(bound_data));
-
- TPM_RESULT status = TPM_SUCCESS;
- TPM_COMMAND_CODE command = TPM_ORD_UnBind;
-
- BYTE *paramText; // Digest to make Auth.
- UINT32 paramTextSize;
-
- // Generate Extra TCS Parameters
- struct pack_buf_t clear_data32;
- BYTE *clear_data_text;
- UINT32 clear_data_size;
-
- // Generate HMAC
- Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
-
- struct pack_buf_t bound_data32 = {bound_data->size, bound_data->bytes};
-
- paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
-
- paramTextSize = BSG_PackList(paramText, 2,
- BSG_TPM_COMMAND_CODE, &command,
- BSG_TPM_SIZE32_DATA, &bound_data32);
-
- TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
- usage_auth, auth) );
-
- // Call TCS
- TPMTRYRETURN( TCSP_UnBind( hContext,
- key_handle,
- buffer_len(bound_data),
- bound_data->bytes,
- auth,
- &clear_data_size,
- &clear_data_text) );
-
-
- // Verify Auth
- clear_data32.size = clear_data_size;
- clear_data32.data = clear_data_text;
- paramTextSize = BSG_PackList(paramText, 3,
- BSG_TPM_RESULT, &status,
- BSG_TPM_COMMAND_CODE, &command,
- BSG_TPM_SIZE32_DATA, &clear_data32);
-
- TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
- usage_auth, auth,
- hContext) );
-
- // Unpack/return key structure
- TPMTRYRETURN(buffer_init(clear_data, 0, 0));
- TPMTRYRETURN(buffer_append_raw (clear_data, clear_data_size,
clear_data_text) );
-
- goto egress;
-
- abort_egress:
-
- egress:
-
- free(paramText);
- TCS_FreeMemory(hContext, clear_data_text);
-
- return status;
-}
-
-TPM_RESULT VTSP_Bind( CRYPTO_INFO *cryptoInfo,
- const buffer_t *inData,
- buffer_t *outData)
-{
- vtpmloginfo(VTPM_LOG_VTSP, "Binding %d bytes of data.\n",
buffer_len(inData));
- TPM_BOUND_DATA boundData;
- UINT32 i;
-
- // Fill boundData's accessory information
- boundData.ver = TPM_STRUCT_VER_1_1;
- boundData.payload = TPM_PT_BIND;
- boundData.payloadData = inData->bytes;
-
- // Pack boundData before encryption
- BYTE* flatBoundData = (BYTE *)malloc(sizeof(BYTE) *
- (sizeof(TPM_VERSION) +
- sizeof(TPM_PAYLOAD_TYPE) +
- buffer_len(inData)));
- if (flatBoundData == NULL) {
- return TPM_NOSPACE;
- }
- UINT32 flatBoundDataSize = 0;
- flatBoundDataSize = BSG_PackList( flatBoundData, 2,
- BSG_TPM_VERSION, &boundData.ver,
- BSG_TYPE_BYTE, &boundData.payload);
-
- memcpy(flatBoundData+flatBoundDataSize, inData->bytes, buffer_len(inData));
- flatBoundDataSize += buffer_len(inData);
-
- BYTE out_tmp[RSA_KEY_SIZE/8]; // RSAEnc does not do blocking, So this is
what will come out.
- UINT32 out_tmp_size;
-
- // Encrypt flatBoundData
- Crypto_RSAEnc( cryptoInfo,
- flatBoundDataSize,
- flatBoundData,
- &out_tmp_size,
- out_tmp);
-
- if (out_tmp_size > RSA_KEY_SIZE/8) {
- // The result of RSAEnc should be a fixed size based on key size.
- vtpmlogerror(VTPM_LOG_VTSP, "Enc buffer just overflowed.\n");
- }
-
- buffer_init(outData, 0, NULL);
- buffer_append_raw(outData, out_tmp_size, out_tmp);
-
- vtpmloginfo(VTPM_LOG_TXDATA, "Bind Generated[%d] = 0x", out_tmp_size);
- for(i = 0 ; i < out_tmp_size ; i++) {
- vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", out_tmp[i]);
- }
- vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
-
- // Free flatBoundData
- free(flatBoundData);
-
- return TPM_SUCCESS;
-}
-
-// Function Reaches into unsupported TCS command, beware.
-TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE hContext,
- const buffer_t *inbuf,
- buffer_t *outbuf ) {
-
- vtpmloginfo(VTPM_LOG_VTSP, "Passthrough in use.\n");
- TPM_RESULT status = TPM_SUCCESS;
-
- // Generate Extra TCS Parameters
- BYTE *resultText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
- UINT32 resultTextSize = TCPA_MAX_BUFFER_LENGTH;
-
- // Call TCS
- TPMTRYRETURN( TCSP_RawTransmitData(buffer_len(inbuf), inbuf->bytes,
- &resultTextSize, resultText) );
-
- // Unpack/return key structure
- TPMTRYRETURN(buffer_init (outbuf, resultTextSize, resultText) );
- goto egress;
-
- abort_egress:
-
- egress:
- TCS_FreeMemory(hContext, resultText);
- free(resultText);
- return status;
-}
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// vtsp.c
+//
+// Higher level interface to TCS for use in service.
+//
+// ==================================================================
+
+#include <string.h>
+#include "tcg.h"
+#include "tcs.h"
+#include "bsg.h"
+#include "log.h"
+#include "crypto.h"
+#include "vtsp.h"
+#include "buffer.h"
+
+#define RSA_KEY_SIZE 0x0800
+
+/***********************************************************************************
+ * GenerateAuth: Generate authorization info to be sent back to application
+ *
+ * Parameters: outParamDigestText The concatenation of output parameters to
be SHA1ed
+ * outParamDigestTextSize Size of inParamDigestText
+ * HMACkey Key to be used for HMACing
+ * For OIAP use key.authUsage or PersistStore.ownerAuth
+ * For OSAP use shared secret
+ * pAuth Authorization information from the application
+ *
+ * Return: TPM_SUCCESS Authorization data created
+ * TPM_AUTHFAIL Invalid (NULL) HMACkey presented for OSAP
+
*************************************************************************************/
+TPM_RESULT GenerateAuth( /*[IN]*/ const BYTE *inParamDigestText,
+ /*[IN]*/ UINT32 inParamDigestTextSize,
+ /*[IN]*/ const TPM_SECRET *HMACkey,
+ /*[IN,OUT]*/ TCS_AUTH *auth) {
+
+ if (inParamDigestText == NULL || auth == NULL)
+ return (TPM_AUTHFAIL);
+ else {
+
+ //Generate new OddNonce
+ Crypto_GetRandom(auth->NonceOdd.nonce, sizeof(TPM_NONCE));
+
+ // Create SHA1 inParamDigest
+ TPM_DIGEST inParamDigest;
+ Crypto_SHA1Full(inParamDigestText, inParamDigestTextSize, (BYTE *)
&inParamDigest);
+
+ // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
+ BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
+
+ BSG_PackList( hmacText, 4,
+ BSG_TPM_DIGEST, &inParamDigest,
+ BSG_TPM_NONCE, &(auth->NonceEven),
+ BSG_TPM_NONCE, &(auth->NonceOdd),
+ BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
+
+ Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText), (BYTE *) HMACkey,
sizeof(TPM_DIGEST), (BYTE *) &(auth->HMAC));
+
+ return(TPM_SUCCESS);
+
+ }
+}
+
+/***********************************************************************************
+ * VerifyAuth: Verify the authdata for a command requiring authorization
+ *
+ * Parameters: inParamDigestText The concatenation of parameters to be SHA1ed
+ * inParamDigestTextSize Size of inParamDigestText
+ * authDataUsage AuthDataUsage for the Entity being used
+ * Key->authDataUsage or TPM_AUTH_OWNER
+ * HMACkey Key to be used for HMACing
+ * For OIAP use key.authUsage or PersistStore.ownerAuth
+ * For OSAP use NULL (It will be aquired from the Auth Session)
+ * If unknown (default), assume OIAP
+ * sessionAuth A TCS_AUTH info for the session
+ * pAuth Authorization information from the application
+ * hContext If specified, on failed Auth, VerifyAuth will
+ * generate a new OIAP session in place
of themselves
+ * destroyed session.
+ *
+ * Return: TPM_SUCCESS Authorization Verified
+ * TPM_AUTHFAIL Authorization Failed
+ * TPM_FAIL Failure during SHA1 routines
+
*************************************************************************************/
+TPM_RESULT VerifyAuth( /*[IN]*/ const BYTE *outParamDigestText,
+ /*[IN]*/ UINT32 outParamDigestTextSize,
+ /*[IN]*/ const TPM_SECRET *HMACkey,
+ /*[IN,OUT]*/ TCS_AUTH *auth,
+ /*[IN]*/ TCS_CONTEXT_HANDLE hContext) {
+ if (outParamDigestText == NULL || auth == NULL)
+ return (TPM_AUTHFAIL);
+
+
+ // Create SHA1 inParamDigest
+ TPM_DIGEST outParamDigest;
+ Crypto_SHA1Full(outParamDigestText, outParamDigestTextSize, (BYTE *)
&outParamDigest);
+
+ // Create HMAC text. (Concat inParamsDigest with inAuthSetupParams).
+ TPM_DIGEST hm;
+ BYTE hmacText[sizeof(TPM_DIGEST) + (2 * sizeof(TPM_NONCE)) + sizeof(BOOL)];
+
+ BSG_PackList( hmacText, 4,
+ BSG_TPM_DIGEST, &outParamDigest,
+ BSG_TPM_NONCE, &(auth->NonceEven),
+ BSG_TPM_NONCE, &(auth->NonceOdd),
+ BSG_TYPE_BOOL, &(auth->fContinueAuthSession) );
+
+ Crypto_HMAC((BYTE *) hmacText, sizeof(hmacText),
+ (BYTE *) HMACkey, sizeof(TPM_DIGEST), (BYTE *) &hm);
+
+ // Compare correct HMAC with provided one.
+ if (memcmp (&hm, &(auth->HMAC), sizeof(TPM_DIGEST)) == 0) // 0 indicates
equality
+ return (TPM_SUCCESS);
+ else {
+ VTSP_OIAP( hContext, auth);
+ return (TPM_AUTHFAIL);
+ }
+}
+
+TPM_RESULT VTSP_OIAP(const TCS_CONTEXT_HANDLE hContext,
+ TCS_AUTH *auth) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "OIAP.\n");
+ TPM_RESULT status = TPM_SUCCESS;
+ TPMTRYRETURN( TCSP_OIAP(hContext,
+ &auth->AuthHandle,
+ &auth->NonceEven) );
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ return status;
+}
+
+TPM_RESULT VTSP_OSAP(const TCS_CONTEXT_HANDLE hContext,
+ const TPM_ENTITY_TYPE entityType,
+ const UINT32 entityValue,
+ const TPM_AUTHDATA *usageAuth,
+ TPM_SECRET *sharedSecret,
+ TCS_AUTH *auth) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "OSAP.\n");
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_NONCE nonceEvenOSAP, nonceOddOSAP;
+
+ Crypto_GetRandom((BYTE *) &nonceOddOSAP, sizeof(TPM_NONCE) );
+
+ TPMTRYRETURN( TCSP_OSAP( hContext,
+ entityType,
+ entityValue,
+ nonceOddOSAP,
+ &auth->AuthHandle,
+ &auth->NonceEven,
+ &nonceEvenOSAP) );
+
+ // Calculating Session Secret
+ BYTE sharedSecretText[TPM_DIGEST_SIZE * 2];
+
+ BSG_PackList( sharedSecretText, 2,
+ BSG_TPM_NONCE, &nonceEvenOSAP,
+ BSG_TPM_NONCE, &nonceOddOSAP);
+
+ Crypto_HMAC(sharedSecretText, sizeof(sharedSecretText), (BYTE *) usageAuth,
TPM_DIGEST_SIZE, (BYTE *) sharedSecret);
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ return status;
+}
+
+
+
+TPM_RESULT VTSP_ReadPubek( const TCS_CONTEXT_HANDLE hContext,
+ CRYPTO_INFO *crypto_info) {
+
+ TPM_RESULT status;
+ TPM_NONCE antiReplay;
+ TPM_DIGEST checksum;
+ BYTE *pubEKtext;
+ UINT32 pubEKtextsize;
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Reading Public EK.\n");
+
+ // GenerateAuth new nonceOdd
+ Crypto_GetRandom(&antiReplay, sizeof(TPM_NONCE) );
+
+
+ TPMTRYRETURN( TCSP_ReadPubek( hContext,
+ antiReplay,
+ &pubEKtextsize,
+ &pubEKtext,
+ &checksum) );
+
+
+ // Extract the remaining output parameters
+ TPM_PUBKEY pubEK;
+
+ BSG_Unpack(BSG_TPM_PUBKEY, pubEKtext, (BYTE *) &pubEK);
+
+ // Build CryptoInfo for the bindingKey
+ TPM_RSA_KEY_PARMS rsaKeyParms;
+
+ BSG_Unpack(BSG_TPM_RSA_KEY_PARMS,
+ pubEK.algorithmParms.parms,
+ &rsaKeyParms);
+
+ Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize,
+ rsaKeyParms.exponent,
+ pubEK.pubKey.keyLength,
+ pubEK.pubKey.key,
+ crypto_info);
+
+ // Destroy rsaKeyParms
+ BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
+
+ // Set encryption scheme
+ crypto_info->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
+ //crypto_info->encScheme = pubEK.algorithmParms.encScheme;
+ crypto_info->algorithmID = pubEK.algorithmParms.algorithmID;
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ return status;
+}
+
+TPM_RESULT VTSP_TakeOwnership( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_AUTHDATA *ownerAuth,
+ const TPM_AUTHDATA *srkAuth,
+ CRYPTO_INFO *ek_cryptoInfo,
+ TCS_AUTH *auth) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Taking Ownership of TPM.\n");
+
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE command = TPM_ORD_TakeOwnership;
+ TPM_PROTOCOL_ID proto_id = TPM_PID_OWNER;
+ BYTE *new_srk;
+
+ BYTE *paramText; // Digest to make Auth.
+ UINT32 paramTextSize;
+
+ // vars for srkpubkey parameter
+ TPM_KEY srkPub;
+ TPM_KEY_PARMS srkKeyInfo = {TPM_ALG_RSA, TPM_ES_RSAESOAEP_SHA1_MGF1,
TPM_SS_NONE, 12, 0};
+ BYTE srkRSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00};
+ srkKeyInfo.parms = (BYTE *) &srkRSAkeyInfo;
+
+ struct pack_buf_t srkText;
+
+ // GenerateAuth new nonceOdd
+ Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
+
+ //These values are accurate for an enc(AuthData).
+ struct pack_buf_t encOwnerAuth, encSrkAuth;
+
+ encOwnerAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
+ encSrkAuth.data = (BYTE *)malloc(sizeof(BYTE) * 256);
+
+ if (encOwnerAuth.data == NULL || encSrkAuth.data == NULL) {
+ vtpmloginfo(VTPM_LOG_VTSP, "Could not malloc encrypted auths.\n");
+ status = TPM_RESOURCES;
+ goto abort_egress;
+ }
+
+ Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) ownerAuth,
&encOwnerAuth.size, encOwnerAuth.data);
+ Crypto_RSAEnc(ek_cryptoInfo, sizeof(TPM_SECRET), (BYTE *) srkAuth,
&encSrkAuth.size, encSrkAuth.data);
+
+
+ // Build srk public key struct
+ srkPub.ver = TPM_STRUCT_VER_1_1;
+ srkPub.keyUsage = TPM_KEY_STORAGE;
+ srkPub.keyFlags = 0x00;
+ srkPub.authDataUsage = TPM_AUTH_ALWAYS;
+ memcpy(&srkPub.algorithmParms, &srkKeyInfo, sizeof(TPM_KEY_PARMS));
+ srkPub.PCRInfoSize = 0;
+ srkPub.PCRInfo = 0;
+ srkPub.pubKey.keyLength= 0;
+ srkPub.encDataSize = 0;
+
+ srkText.data = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+ srkText.size = BSG_Pack(BSG_TPM_KEY, (BYTE *) &srkPub, srkText.data);
+
+ paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+
+ paramTextSize = BSG_PackList(paramText, 5,
+ BSG_TPM_COMMAND_CODE,&command,
+ BSG_TPM_PROTOCOL_ID, &proto_id,
+ BSG_TPM_SIZE32_DATA, &encOwnerAuth,
+ BSG_TPM_SIZE32_DATA, &encSrkAuth,
+ BSG_TPM_KEY, &srkPub);
+
+ TPMTRYRETURN( GenerateAuth( paramText, paramTextSize, ownerAuth, auth) );
+
+ new_srk = srkText.data;
+ TPMTRYRETURN( TCSP_TakeOwnership ( hContext,
+ proto_id,
+ encOwnerAuth.size,
+ encOwnerAuth.data,
+ encSrkAuth.size,
+ encSrkAuth.data,
+ &srkText.size,
+ &new_srk,
+ auth ) );
+
+
+ paramTextSize = BSG_PackList(paramText, 2,
+ BSG_TPM_RESULT, &status,
+ BSG_TPM_COMMAND_CODE, &command);
+ memcpy(paramText + paramTextSize, new_srk, srkText.size);
+ paramTextSize += srkText.size;
+
+
+ TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
+ ownerAuth, auth,
+ hContext) );
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ free(srkText.data);
+ free(encSrkAuth.data);
+ free(encOwnerAuth.data);
+ free(paramText);
+
+ TCS_FreeMemory(hContext, new_srk);
+
+ return status;
+}
+
+TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_AUTHDATA *ownerAuth,
+ TCS_AUTH *auth) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Disabling Pubek Read.\n");
+
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE command = TPM_ORD_DisablePubekRead;
+
+ BYTE *paramText; // Digest to make Auth.
+ UINT32 paramTextSize;
+
+ // Generate HMAC
+ Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
+
+ paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+
+ paramTextSize = BSG_PackList(paramText, 1,
+ BSG_TPM_COMMAND_CODE, &command);
+
+ TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
+ ownerAuth, auth) );
+
+ // Call TCS
+ TPMTRYRETURN( TCSP_DisablePubekRead ( hContext, // in
+ auth) );
+
+ // Verify Auth
+ paramTextSize = BSG_PackList(paramText, 2,
+ BSG_TPM_RESULT, &status,
+ BSG_TPM_COMMAND_CODE, &command);
+
+ TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
+ ownerAuth, auth,
+ hContext) );
+ goto egress;
+
+ abort_egress:
+ egress:
+ free(paramText);
+ return status;
+}
+
+TPM_RESULT VTSP_CreateWrapKey( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_KEY_USAGE usage,
+ const TPM_AUTHDATA *newKeyAuth,
+ const TCS_KEY_HANDLE parentHandle,
+ const TPM_AUTHDATA *osapSharedSecret,
+ buffer_t *pubKeyBuf,
+ TCS_AUTH *auth) {
+
+ int i;
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE command = TPM_ORD_CreateWrapKey;
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Creating new key of type %d.\n", usage);
+
+ // vars for Calculate encUsageAuth
+ BYTE *paramText;
+ UINT32 paramTextSize;
+
+ // vars for Calculate encUsageAuth
+ BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
+ TPM_DIGEST XORKey1;
+ UINT32 XORbufferSize;
+ TPM_SECRET encUsageAuth, encMigrationAuth;
+
+ // vars for Flatten newKey prototype
+ BYTE *flatKey = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+ UINT32 flatKeySize = TCPA_MAX_BUFFER_LENGTH;
+ struct pack_buf_t newKeyText;
+
+ // Fill in newKey
+ TPM_KEY newKey;
+
+ BYTE RSAkeyInfo[12] = { 0x00, 0x00, (RSA_KEY_SIZE >> 8), 0x00, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00};
+ newKey.algorithmParms.algorithmID = TPM_ALG_RSA;
+ newKey.algorithmParms.parms = (BYTE *) &RSAkeyInfo;
+ newKey.algorithmParms.parmSize = 12;
+
+ switch (usage) {
+ case TPM_KEY_SIGNING:
+ vtpmloginfo(VTPM_LOG_VTSP, "Creating Signing Key...\n");
+ newKey.keyUsage = TPM_KEY_SIGNING;
+ newKey.algorithmParms.encScheme = TPM_ES_NONE;
+ newKey.algorithmParms.sigScheme = TPM_SS_RSASSAPKCS1v15_SHA1;
+ break;
+ case TPM_KEY_STORAGE:
+ vtpmloginfo(VTPM_LOG_VTSP, "Creating Storage Key...\n");
+ newKey.keyUsage = TPM_KEY_STORAGE;
+ newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
+ newKey.algorithmParms.sigScheme = TPM_SS_NONE;
+ break;
+ case TPM_KEY_BIND:
+ vtpmloginfo(VTPM_LOG_VTSP, "Creating Binding Key...\n");
+ newKey.keyUsage = TPM_KEY_BIND;
+ newKey.algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
+ newKey.algorithmParms.sigScheme = TPM_SS_NONE;
+ break;
+ default:
+ vtpmloginfo(VTPM_LOG_VTSP, "Cannot create key. Invalid Key Type.\n");
+ status = TPM_BAD_PARAMETER;
+ goto abort_egress;
+ }
+
+
+ newKey.ver = TPM_STRUCT_VER_1_1;
+
+ newKey.keyFlags = 0;
+ newKey.authDataUsage = TPM_AUTH_ALWAYS;
+ newKey.pubKey.keyLength= 0;
+ newKey.encDataSize = 0;
+ newKey.encData = NULL;
+
+ // FIXME: Support PCR bindings
+ newKey.PCRInfoSize = 0;
+ newKey.PCRInfo = NULL;
+
+ // Calculate encUsageAuth
+ XORbufferSize = BSG_PackList( XORbuffer, 2,
+ BSG_TPM_SECRET, osapSharedSecret,
+ BSG_TPM_NONCE, &auth->NonceEven);
+ Crypto_SHA1Full(XORbuffer, XORbufferSize, (BYTE *) &XORKey1);
+
+ // FIXME: No support for migratable keys.
+ for (i=0; i < TPM_DIGEST_SIZE; i++)
+ ((BYTE *) &encUsageAuth)[i] = ((BYTE *) &XORKey1)[i] ^ ((BYTE *)
newKeyAuth)[i];
+
+ // Flatten newKey prototype
+ flatKeySize = BSG_Pack(BSG_TPM_KEY, (BYTE *) &newKey, flatKey);
+ newKeyText.data = flatKey;
+ newKeyText.size = flatKeySize;
+
+ // GenerateAuth new nonceOdd
+ Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
+
+ // Generate HMAC
+ paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+
+ paramTextSize = BSG_PackList(paramText, 3,
+ BSG_TPM_COMMAND_CODE, &command,
+ BSG_TPM_AUTHDATA, &encUsageAuth,
+ BSG_TPM_AUTHDATA, &encMigrationAuth);
+ memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
+ paramTextSize += newKeyText.size;
+
+
+ TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
+ osapSharedSecret, auth) );
+
+ // Call TCS
+ TPMTRYRETURN( TCSP_CreateWrapKey( hContext,
+ parentHandle,
+ encUsageAuth,
+ encMigrationAuth,
+ &newKeyText.size,
+ &newKeyText.data,
+ auth) );
+
+ // Verify Auth
+ paramTextSize = BSG_PackList(paramText, 2,
+ BSG_TPM_RESULT, &status,
+ BSG_TPM_COMMAND_CODE, &command);
+ memcpy(paramText + paramTextSize, newKeyText.data, newKeyText.size);
+ paramTextSize += newKeyText.size;
+
+ TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
+ osapSharedSecret, auth, 0) );
+
+ // Unpack/return key structure
+ TPMTRYRETURN(buffer_init(pubKeyBuf, 0, 0) );
+ TPMTRYRETURN(buffer_append_raw(pubKeyBuf, newKeyText.size, newKeyText.data)
);
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ free(flatKey);
+ free(paramText);
+ TCS_FreeMemory(hContext, newKeyText.data);
+
+ return status;
+}
+
+TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE hContext,
+ const TCS_KEY_HANDLE hUnwrappingKey,
+ const buffer_t *rgbWrappedKeyBlob,
+ const TPM_AUTHDATA *parentAuth,
+ TPM_HANDLE *newKeyHandle,
+ TCS_AUTH *auth,
+ CRYPTO_INFO *cryptoinfo /*= NULL*/) {
+
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Loading Key.\n%s","");
+
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE command = TPM_ORD_LoadKey;
+
+ BYTE *paramText; // Digest to make Auth.
+ UINT32 paramTextSize;
+
+ if ((rgbWrappedKeyBlob == NULL) || (parentAuth == NULL) ||
+ (newKeyHandle==NULL) || (auth==NULL)) {
+ status = TPM_BAD_PARAMETER;
+ goto abort_egress;
+ }
+
+ // Generate Extra TCS Parameters
+ TPM_HANDLE phKeyHMAC;
+
+ // Generate HMAC
+ Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
+
+ paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+
+ paramTextSize = BSG_PackList(paramText, 1,
+ BSG_TPM_COMMAND_CODE, &command);
+
+ memcpy(paramText + paramTextSize, rgbWrappedKeyBlob->bytes,
buffer_len(rgbWrappedKeyBlob));
+ paramTextSize += buffer_len(rgbWrappedKeyBlob);
+
+ TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
+ parentAuth, auth) );
+
+ // Call TCS
+ TPMTRYRETURN( TCSP_LoadKeyByBlob( hContext,
+ hUnwrappingKey,
+ buffer_len(rgbWrappedKeyBlob),
+ rgbWrappedKeyBlob->bytes,
+ auth,
+ newKeyHandle,
+ &phKeyHMAC) );
+
+ // Verify Auth
+ paramTextSize = BSG_PackList(paramText, 3,
+ BSG_TPM_RESULT, &status,
+ BSG_TPM_COMMAND_CODE, &command,
+ BSG_TPM_HANDLE, newKeyHandle);
+
+ TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
+ parentAuth, auth,
+ hContext) );
+
+ // Unpack/return key structure
+ if (cryptoinfo != NULL) {
+ TPM_KEY newKey;
+
+ BSG_Unpack(BSG_TPM_KEY, rgbWrappedKeyBlob->bytes , &newKey);
+ TPM_RSA_KEY_PARMS rsaKeyParms;
+
+ BSG_Unpack(BSG_TPM_RSA_KEY_PARMS,
+ newKey.algorithmParms.parms,
+ &rsaKeyParms);
+
+ Crypto_RSABuildCryptoInfoPublic(rsaKeyParms.exponentSize,
+ rsaKeyParms.exponent,
+ newKey.pubKey.keyLength,
+ newKey.pubKey.key,
+ cryptoinfo);
+
+ // Destroy rsaKeyParms
+ BSG_Destroy(BSG_TPM_RSA_KEY_PARMS, &rsaKeyParms);
+
+ // Set encryption scheme
+ cryptoinfo->encScheme = CRYPTO_ES_RSAESOAEP_SHA1_MGF1;
+ }
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ free(paramText);
+ return status;
+}
+
+TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_KEY_HANDLE key_handle,
+ const buffer_t *bound_data,
+ const TPM_AUTHDATA *usage_auth,
+ buffer_t *clear_data,
+ TCS_AUTH *auth) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Unbinding %d bytes of data.\n",
buffer_len(bound_data));
+
+ TPM_RESULT status = TPM_SUCCESS;
+ TPM_COMMAND_CODE command = TPM_ORD_UnBind;
+
+ BYTE *paramText; // Digest to make Auth.
+ UINT32 paramTextSize;
+
+ // Generate Extra TCS Parameters
+ struct pack_buf_t clear_data32;
+ BYTE *clear_data_text;
+ UINT32 clear_data_size;
+
+ // Generate HMAC
+ Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
+
+ struct pack_buf_t bound_data32 = {bound_data->size, bound_data->bytes};
+
+ paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+
+ paramTextSize = BSG_PackList(paramText, 2,
+ BSG_TPM_COMMAND_CODE, &command,
+ BSG_TPM_SIZE32_DATA, &bound_data32);
+
+ TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
+ usage_auth, auth) );
+
+ // Call TCS
+ TPMTRYRETURN( TCSP_UnBind( hContext,
+ key_handle,
+ buffer_len(bound_data),
+ bound_data->bytes,
+ auth,
+ &clear_data_size,
+ &clear_data_text) );
+
+
+ // Verify Auth
+ clear_data32.size = clear_data_size;
+ clear_data32.data = clear_data_text;
+ paramTextSize = BSG_PackList(paramText, 3,
+ BSG_TPM_RESULT, &status,
+ BSG_TPM_COMMAND_CODE, &command,
+ BSG_TPM_SIZE32_DATA, &clear_data32);
+
+ TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
+ usage_auth, auth,
+ hContext) );
+
+ // Unpack/return key structure
+ TPMTRYRETURN(buffer_init(clear_data, 0, 0));
+ TPMTRYRETURN(buffer_append_raw (clear_data, clear_data_size,
clear_data_text) );
+
+ goto egress;
+
+ abort_egress:
+
+ egress:
+
+ free(paramText);
+ TCS_FreeMemory(hContext, clear_data_text);
+
+ return status;
+}
+
+TPM_RESULT VTSP_Bind( CRYPTO_INFO *cryptoInfo,
+ const buffer_t *inData,
+ buffer_t *outData)
+{
+ vtpmloginfo(VTPM_LOG_VTSP, "Binding %d bytes of data.\n",
buffer_len(inData));
+ TPM_BOUND_DATA boundData;
+ UINT32 i;
+
+ // Fill boundData's accessory information
+ boundData.ver = TPM_STRUCT_VER_1_1;
+ boundData.payload = TPM_PT_BIND;
+ boundData.payloadData = inData->bytes;
+
+ // Pack boundData before encryption
+ BYTE* flatBoundData = (BYTE *)malloc(sizeof(BYTE) *
+ (sizeof(TPM_VERSION) +
+ sizeof(TPM_PAYLOAD_TYPE) +
+ buffer_len(inData)));
+ if (flatBoundData == NULL) {
+ return TPM_NOSPACE;
+ }
+ UINT32 flatBoundDataSize = 0;
+ flatBoundDataSize = BSG_PackList( flatBoundData, 2,
+ BSG_TPM_VERSION, &boundData.ver,
+ BSG_TYPE_BYTE, &boundData.payload);
+
+ memcpy(flatBoundData+flatBoundDataSize, inData->bytes, buffer_len(inData));
+ flatBoundDataSize += buffer_len(inData);
+
+ BYTE out_tmp[RSA_KEY_SIZE/8]; // RSAEnc does not do blocking, So this is
what will come out.
+ UINT32 out_tmp_size;
+
+ // Encrypt flatBoundData
+ Crypto_RSAEnc( cryptoInfo,
+ flatBoundDataSize,
+ flatBoundData,
+ &out_tmp_size,
+ out_tmp);
+
+ if (out_tmp_size > RSA_KEY_SIZE/8) {
+ // The result of RSAEnc should be a fixed size based on key size.
+ vtpmlogerror(VTPM_LOG_VTSP, "Enc buffer just overflowed.\n");
+ }
+
+ buffer_init(outData, 0, NULL);
+ buffer_append_raw(outData, out_tmp_size, out_tmp);
+
+ vtpmloginfo(VTPM_LOG_TXDATA, "Bind Generated[%d] = 0x", out_tmp_size);
+ for(i = 0 ; i < out_tmp_size ; i++) {
+ vtpmloginfomore(VTPM_LOG_TXDATA, "%2.2x ", out_tmp[i]);
+ }
+ vtpmloginfomore(VTPM_LOG_TXDATA, "\n");
+
+ // Free flatBoundData
+ free(flatBoundData);
+
+ return TPM_SUCCESS;
+}
+
+// Function Reaches into unsupported TCS command, beware.
+TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE hContext,
+ const buffer_t *inbuf,
+ buffer_t *outbuf ) {
+
+ vtpmloginfo(VTPM_LOG_VTSP, "Passthrough in use.\n");
+ TPM_RESULT status = TPM_SUCCESS;
+
+ // Generate Extra TCS Parameters
+ BYTE *resultText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
+ UINT32 resultTextSize = TCPA_MAX_BUFFER_LENGTH;
+
+ // Call TCS
+ TPMTRYRETURN( TCSP_RawTransmitData(buffer_len(inbuf), inbuf->bytes,
+ &resultTextSize, resultText) );
+
+ // Unpack/return key structure
+ TPMTRYRETURN(buffer_init (outbuf, resultTextSize, resultText) );
+ goto egress;
+
+ abort_egress:
+
+ egress:
+ TCS_FreeMemory(hContext, resultText);
+ free(resultText);
+ return status;
+}
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/manager/vtsp.h
--- a/tools/vtpm_manager/manager/vtsp.h Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/manager/vtsp.h Wed Nov 30 19:55:08 2005
@@ -1,102 +1,102 @@
-// ===================================================================
-//
-// Copyright (c) 2005, Intel Corp.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Intel Corporation nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-// OF THE POSSIBILITY OF SUCH DAMAGE.
-// ===================================================================
-//
-// vtsp.h
-//
-// Higher level interface to TCS.
-//
-// ==================================================================
-
-#ifndef __VTSP_H__
-#define __VTSP_H__
-
-#include "tcg.h"
-#include "tcs.h"
-
-#define KEY_BUFFER_SIZE 2048
-
-TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE hContext,
- const buffer_t *inbuf,
- buffer_t *outbuf );
-
-TPM_RESULT VTSP_OIAP( const TCS_CONTEXT_HANDLE hContext,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_OSAP( const TCS_CONTEXT_HANDLE hContext,
- const TPM_ENTITY_TYPE entityType,
- const UINT32 entityValue,
- const TPM_AUTHDATA *usageAuth,
- TPM_SECRET *sharedsecret,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_ReadPubek( const TCS_CONTEXT_HANDLE hContext,
- CRYPTO_INFO *cypto_info);
-
-TPM_RESULT VTSP_TakeOwnership( const TCS_CONTEXT_HANDLE hContext,
- const TPM_AUTHDATA *ownerAuth,
- const TPM_AUTHDATA *srkAuth,
- CRYPTO_INFO *ek_cryptoInfo,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE hContext,
- const TPM_AUTHDATA *ownerAuth,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_CreateWrapKey( const TCS_CONTEXT_HANDLE hContext,
- const TPM_KEY_USAGE usage,
- const TPM_AUTHDATA *newKeyAuth,
- const TCS_KEY_HANDLE parentHandle,
- const TPM_AUTHDATA *osapSharedSecret,
- buffer_t *pubKeyBuf,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE hContext,
- const TCS_KEY_HANDLE hUnwrappingKey,
- const buffer_t *rgbWrappedKeyBlob,
- const TPM_AUTHDATA *parentAuth,
- TPM_HANDLE *newKeyHandle,
- TCS_AUTH *pAuth,
- CRYPTO_INFO *cryptoinfo);
-
-TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE hContext,
- const TPM_KEY_HANDLE key_handle,
- const buffer_t *bound_data,
- const TPM_AUTHDATA *usage_auth,
- buffer_t *clear_data,
- TCS_AUTH *auth);
-
-TPM_RESULT VTSP_Bind( CRYPTO_INFO *cryptoInfo,
- const buffer_t *inData,
- buffer_t *outData);
-
-#endif //_VTSP_H_
+// ===================================================================
+//
+// Copyright (c) 2005, Intel Corp.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Intel Corporation nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+// ===================================================================
+//
+// vtsp.h
+//
+// Higher level interface to TCS.
+//
+// ==================================================================
+
+#ifndef __VTSP_H__
+#define __VTSP_H__
+
+#include "tcg.h"
+#include "tcs.h"
+
+#define KEY_BUFFER_SIZE 2048
+
+TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE hContext,
+ const buffer_t *inbuf,
+ buffer_t *outbuf );
+
+TPM_RESULT VTSP_OIAP( const TCS_CONTEXT_HANDLE hContext,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_OSAP( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_ENTITY_TYPE entityType,
+ const UINT32 entityValue,
+ const TPM_AUTHDATA *usageAuth,
+ TPM_SECRET *sharedsecret,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_ReadPubek( const TCS_CONTEXT_HANDLE hContext,
+ CRYPTO_INFO *cypto_info);
+
+TPM_RESULT VTSP_TakeOwnership( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_AUTHDATA *ownerAuth,
+ const TPM_AUTHDATA *srkAuth,
+ CRYPTO_INFO *ek_cryptoInfo,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_DisablePubekRead( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_AUTHDATA *ownerAuth,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_CreateWrapKey( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_KEY_USAGE usage,
+ const TPM_AUTHDATA *newKeyAuth,
+ const TCS_KEY_HANDLE parentHandle,
+ const TPM_AUTHDATA *osapSharedSecret,
+ buffer_t *pubKeyBuf,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_LoadKey(const TCS_CONTEXT_HANDLE hContext,
+ const TCS_KEY_HANDLE hUnwrappingKey,
+ const buffer_t *rgbWrappedKeyBlob,
+ const TPM_AUTHDATA *parentAuth,
+ TPM_HANDLE *newKeyHandle,
+ TCS_AUTH *pAuth,
+ CRYPTO_INFO *cryptoinfo);
+
+TPM_RESULT VTSP_Unbind( const TCS_CONTEXT_HANDLE hContext,
+ const TPM_KEY_HANDLE key_handle,
+ const buffer_t *bound_data,
+ const TPM_AUTHDATA *usage_auth,
+ buffer_t *clear_data,
+ TCS_AUTH *auth);
+
+TPM_RESULT VTSP_Bind( CRYPTO_INFO *cryptoInfo,
+ const buffer_t *inData,
+ buffer_t *outData);
+
+#endif //_VTSP_H_
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/util/Makefile
--- a/tools/vtpm_manager/util/Makefile Wed Nov 30 19:54:28 2005
+++ b/tools/vtpm_manager/util/Makefile Wed Nov 30 19:55:08 2005
@@ -1,19 +1,19 @@
-XEN_ROOT = ../../..
-include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
-
-BIN = libTCGUtils.a
-
-all: build
-
-build: $(BIN)
-
-install: build
-
-clean:
- rm -f *.a *.so *.o *.rpm $(DEP_FILES)
-
-mrproper: clean
- rm -f *~
-
-$(BIN): $(OBJS)
- $(AR) rcs $(BIN) $(OBJS)
+XEN_ROOT = ../../..
+include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk
+
+BIN = libTCGUtils.a
+
+all: build
+
+build: $(BIN)
+
+install: build
+
+clean:
+ rm -f *.a *.so *.o *.rpm $(DEP_FILES)
+
+mrproper: clean
+ rm -f *~
+
+$(BIN): $(OBJS)
+ $(AR) rcs $(BIN) $(OBJS)
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/dm/i8259.c
--- a/xen/arch/x86/dm/i8259.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/dm/i8259.c Wed Nov 30 19:55:08 2005
@@ -31,7 +31,7 @@
#include <xen/sched.h>
#include <public/io/ioreq.h>
#include <asm/vmx.h>
-#include <public/io/vmx_vpic.h>
+#include <asm/vmx_vpic.h>
#include <asm/current.h>
#include <asm/vmx_vioapic.h>
#include <asm/vmx_vlapic.h>
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/dm/vmx_vioapic.c
--- a/xen/arch/x86/dm/vmx_vioapic.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/dm/vmx_vioapic.c Wed Nov 30 19:55:08 2005
@@ -39,7 +39,7 @@
#include <xen/sched.h>
#include <public/io/ioreq.h>
#include <asm/vmx.h>
-#include <public/io/vmx_vpic.h>
+#include <asm/vmx_vpic.h>
#include <asm/current.h>
static void ioapic_enable(vmx_vioapic_t *s, uint8_t enable)
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/dom0_ops.c
--- a/xen/arch/x86/dom0_ops.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/dom0_ops.c Wed Nov 30 19:55:08 2005
@@ -144,7 +144,7 @@
unsigned int p;
ret = -EINVAL;
- if ( (fp + np) >= 65536 )
+ if ( (fp + np) > 65536 )
break;
ret = -ESRCH;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/shadow.c
--- a/xen/arch/x86/shadow.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/shadow.c Wed Nov 30 19:55:08 2005
@@ -2154,7 +2154,8 @@
#elif CONFIG_PAGING_LEVELS == 4
smfn = shadow_l4_table(d, gpfn, gmfn);
#endif
- }
+ }else
+ shadow_sync_all(d);
if ( !get_shadow_ref(smfn) )
BUG();
old_smfn = pagetable_get_pfn(v->arch.shadow_table);
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/shadow32.c
--- a/xen/arch/x86/shadow32.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/shadow32.c Wed Nov 30 19:55:08 2005
@@ -2911,6 +2911,8 @@
*/
if ( unlikely(!(smfn = __shadow_status(d, gpfn, PGT_base_page_table))) )
smfn = shadow_l2_table(d, gpfn, gmfn);
+ else
+ shadow_sync_all(d);
if ( !get_shadow_ref(smfn) )
BUG();
old_smfn = pagetable_get_pfn(v->arch.shadow_table);
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/vmx.c
--- a/xen/arch/x86/vmx.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/vmx.c Wed Nov 30 19:55:08 2005
@@ -43,8 +43,8 @@
#endif
#include <public/sched.h>
#include <public/io/ioreq.h>
-#include <public/io/vmx_vpic.h>
-#include <public/io/vmx_vlapic.h>
+#include <asm/vmx_vpic.h>
+#include <asm/vmx_vlapic.h>
int hvm_enabled;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/vmx_intercept.c
--- a/xen/arch/x86/vmx_intercept.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/vmx_intercept.c Wed Nov 30 19:55:08 2005
@@ -21,7 +21,7 @@
#include <xen/types.h>
#include <asm/vmx.h>
#include <asm/vmx_platform.h>
-#include <asm/vmx_virpit.h>
+#include <asm/vmx_vpit.h>
#include <asm/vmx_intercept.h>
#include <asm/vmx_vlapic.h>
#include <public/io/ioreq.h>
diff -r 6a2acc1cc505 -r 28ce48573771 xen/arch/x86/vmx_io.c
--- a/xen/arch/x86/vmx_io.c Wed Nov 30 19:54:28 2005
+++ b/xen/arch/x86/vmx_io.c Wed Nov 30 19:55:08 2005
@@ -32,13 +32,12 @@
#include <asm/vmx.h>
#include <asm/vmx_vmcs.h>
#include <asm/vmx_platform.h>
-#include <asm/vmx_virpit.h>
+#include <asm/vmx_vpit.h>
#include <asm/apic.h>
#include <asm/shadow.h>
-
+#include <asm/vmx_vpic.h>
#include <asm/vmx_vlapic.h>
#include <public/io/ioreq.h>
-#include <public/io/vmx_vpic.h>
#ifdef CONFIG_VMX
#if defined (__i386__)
diff -r 6a2acc1cc505 -r 28ce48573771 xen/common/domain.c
--- a/xen/common/domain.c Wed Nov 30 19:54:28 2005
+++ b/xen/common/domain.c Wed Nov 30 19:55:08 2005
@@ -293,11 +293,7 @@
struct vcpu *v;
for_each_vcpu( d, v )
- {
- BUG_ON(v == current);
- atomic_inc(&v->pausecnt);
- vcpu_sleep_sync(v);
- }
+ vcpu_pause(v);
sync_pagetable_state(d);
}
diff -r 6a2acc1cc505 -r 28ce48573771 xen/common/grant_table.c
--- a/xen/common/grant_table.c Wed Nov 30 19:54:28 2005
+++ b/xen/common/grant_table.c Wed Nov 30 19:55:08 2005
@@ -114,13 +114,13 @@
(GNTMAP_device_map|GNTMAP_host_map)) == 0) )
{
DPRINTK("Bad ref (%d) or flags (%x).\n", ref, dev_hst_ro_flags);
- (void)__put_user(GNTST_bad_gntref, &uop->handle);
+ (void)__put_user(GNTST_bad_gntref, &uop->status);
return GNTST_bad_gntref;
}
if ( acm_pre_grant_map_ref(dom) )
{
- (void)__put_user(GNTST_permission_denied, &uop->handle);
+ (void)__put_user(GNTST_permission_denied, &uop->status);
return GNTST_permission_denied;
}
@@ -130,7 +130,7 @@
if ( rd != NULL )
put_domain(rd);
DPRINTK("Could not find domain %d\n", dom);
- (void)__put_user(GNTST_bad_domain, &uop->handle);
+ (void)__put_user(GNTST_bad_domain, &uop->status);
return GNTST_bad_domain;
}
@@ -145,7 +145,7 @@
{
put_domain(rd);
DPRINTK("Maptrack table is at maximum size.\n");
- (void)__put_user(GNTST_no_device_space, &uop->handle);
+ (void)__put_user(GNTST_no_device_space, &uop->status);
return GNTST_no_device_space;
}
@@ -155,7 +155,7 @@
{
put_domain(rd);
DPRINTK("No more map handles available.\n");
- (void)__put_user(GNTST_no_device_space, &uop->handle);
+ (void)__put_user(GNTST_no_device_space, &uop->status);
return GNTST_no_device_space;
}
@@ -370,6 +370,7 @@
(void)__put_user((u64)frame << PAGE_SHIFT, &uop->dev_bus_addr);
(void)__put_user(handle, &uop->handle);
+ (void)__put_user(GNTST_okay, &uop->status);
put_domain(rd);
return rc;
@@ -377,7 +378,7 @@
unlock_out:
spin_unlock(&rd->grant_table->lock);
- (void)__put_user(rc, &uop->handle);
+ (void)__put_user(rc, &uop->status);
put_maptrack_handle(ld->grant_table, handle);
return rc;
}
@@ -400,7 +401,7 @@
{
domid_t dom;
grant_ref_t ref;
- u16 handle;
+ grant_handle_t handle;
struct domain *ld, *rd;
active_grant_entry_t *act;
grant_entry_t *sha;
@@ -957,7 +958,7 @@
grant_table_t *gt = d->grant_table;
grant_mapping_t *map;
grant_ref_t ref;
- u16 handle;
+ grant_handle_t handle;
struct domain *rd;
active_grant_entry_t *act;
grant_entry_t *sha;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/asm-x86/shadow.h
--- a/xen/include/asm-x86/shadow.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/asm-x86/shadow.h Wed Nov 30 19:55:08 2005
@@ -317,7 +317,7 @@
unsigned long gpfn; /* why is this here? */
unsigned long gmfn;
unsigned long snapshot_mfn;
- unsigned long writable_pl1e; /* NB: this is a machine address */
+ physaddr_t writable_pl1e; /* NB: this is a machine address */
unsigned long va;
};
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/asm-x86/vmx_platform.h
--- a/xen/include/asm-x86/vmx_platform.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/asm-x86/vmx_platform.h Wed Nov 30 19:55:08 2005
@@ -22,10 +22,10 @@
#include <public/xen.h>
#include <asm/e820.h>
-#include <asm/vmx_virpit.h>
+#include <asm/vmx_vpit.h>
#include <asm/vmx_intercept.h>
#include <asm/vmx_vioapic.h>
-#include <public/io/vmx_vpic.h>
+#include <asm/vmx_vpic.h>
#define MAX_OPERAND_NUM 2
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/acm_ops.h
--- a/xen/include/public/acm_ops.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/acm_ops.h Wed Nov 30 19:55:08 2005
@@ -63,7 +63,7 @@
ssidref_t ssidref;
} id;
void *ssidbuf;
- uint16_t ssidbuf_size;
+ uint32_t ssidbuf_size;
};
#define ACM_GETDECISION 8
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/dom0_ops.h
--- a/xen/include/public/dom0_ops.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/dom0_ops.h Wed Nov 30 19:55:08 2005
@@ -19,7 +19,7 @@
* This makes sure that old versions of dom0 tools will stop working in a
* well-defined way (rather than crashing the machine, for instance).
*/
-#define DOM0_INTERFACE_VERSION 0xAAAA1012
+#define DOM0_INTERFACE_VERSION 0xAAAA1014
/************************************************************************/
@@ -98,7 +98,7 @@
typedef struct {
/* IN variables. */
domid_t domain;
- uint16_t vcpu;
+ uint32_t vcpu;
/* IN/OUT parameters */
vcpu_guest_context_t *ctxt;
} dom0_setdomaininfo_t;
@@ -107,7 +107,7 @@
typedef struct {
/* IN variables. */
uint32_t write;
- uint32_t cpu_mask;
+ cpumap_t cpu_mask;
uint32_t msr;
uint32_t in1;
uint32_t in2;
@@ -115,21 +115,6 @@
uint32_t out1;
uint32_t out2;
} dom0_msr_t;
-
-#define DOM0_DEBUG 16
-typedef struct {
- /* IN variables. */
- domid_t domain;
- uint8_t opcode;
- uint32_t in1;
- uint32_t in2;
- uint32_t in3;
- uint32_t in4;
- /* OUT variables. */
- uint32_t status;
- uint32_t out1;
- uint32_t out2;
-} dom0_debug_t;
/*
* Set clock such that it would read <secs,nsecs> after 00:00:00 UTC,
@@ -182,8 +167,8 @@
typedef struct {
/* IN variables. */
domid_t domain;
- uint16_t vcpu;
- cpumap_t cpumap;
+ uint32_t vcpu;
+ cpumap_t cpumap;
} dom0_pincpudomain_t;
/* Get trace buffers machine base address */
@@ -196,9 +181,9 @@
#define DOM0_TBUF_SET_SIZE 3
#define DOM0_TBUF_ENABLE 4
#define DOM0_TBUF_DISABLE 5
- uint8_t op;
+ uint32_t op;
/* IN/OUT variables */
- unsigned long cpu_mask;
+ cpumap_t cpu_mask;
uint32_t evt_mask;
/* OUT variables */
unsigned long buffer_mfn;
@@ -327,7 +312,7 @@
#define DOM0_PERFCCONTROL_OP_RESET 1 /* Reset all counters to zero. */
#define DOM0_PERFCCONTROL_OP_QUERY 2 /* Get perfctr information. */
typedef struct {
- uint8_t name[80]; /* name of perf counter */
+ uint8_t name[80]; /* name of perf counter */
uint32_t nr_vals; /* number of values for this counter */
uint32_t vals[64]; /* array of values */
} dom0_perfc_desc_t;
@@ -349,16 +334,16 @@
#define DOM0_IOPORT_PERMISSION 36
typedef struct {
domid_t domain; /* domain to be affected */
- uint16_t first_port; /* first port int range */
- uint16_t nr_ports; /* size of port range */
- uint16_t allow_access; /* allow or deny access to range? */
+ uint32_t first_port; /* first port int range */
+ uint32_t nr_ports; /* size of port range */
+ uint8_t allow_access; /* allow or deny access to range? */
} dom0_ioport_permission_t;
#define DOM0_GETVCPUCONTEXT 37
typedef struct {
/* IN variables. */
domid_t domain; /* domain to be affected */
- uint16_t vcpu; /* vcpu # */
+ uint32_t vcpu; /* vcpu # */
/* OUT variables. */
vcpu_guest_context_t *ctxt;
} dom0_getvcpucontext_t;
@@ -367,7 +352,7 @@
typedef struct {
/* IN variables. */
domid_t domain; /* domain to be affected */
- uint16_t vcpu; /* vcpu # */
+ uint32_t vcpu; /* vcpu # */
/* OUT variables. */
uint8_t online; /* currently online (not hotplugged)? */
uint8_t blocked; /* blocked waiting for an event? */
@@ -381,35 +366,36 @@
typedef struct {
/* IN variables. */
domid_t first_domain;
- unsigned int max_domains;
+ uint32_t max_domains;
dom0_getdomaininfo_t *buffer;
/* OUT variables. */
- unsigned int num_domains;
+ uint32_t num_domains;
} dom0_getdomaininfolist_t;
#define DOM0_PLATFORM_QUIRK 39
#define QUIRK_NOIRQBALANCING 1
typedef struct {
/* IN variables. */
- int quirk_id;
+ uint32_t quirk_id;
} dom0_platform_quirk_t;
#define DOM0_PHYSICAL_MEMORY_MAP 40
typedef struct {
/* IN variables. */
- int max_map_entries;
- /* OUT variables. */
- int nr_map_entries;
+ uint32_t max_map_entries;
+ /* OUT variables. */
+ uint32_t nr_map_entries;
struct dom0_memory_map_entry {
uint64_t start, end;
- int is_ram;
+ uint32_t flags; /* reserved */
+ uint8_t is_ram;
} *memory_map;
} dom0_physical_memory_map_t;
#define DOM0_MAX_VCPUS 41
typedef struct {
- domid_t domain; /* domain to be affected */
- unsigned int max; /* maximum number of vcpus */
+ domid_t domain; /* domain to be affected */
+ uint32_t max; /* maximum number of vcpus */
} dom0_max_vcpus_t;
#define DOM0_SETDOMAINHANDLE 44
@@ -433,7 +419,6 @@
dom0_getdomaininfo_t getdomaininfo;
dom0_getpageframeinfo_t getpageframeinfo;
dom0_msr_t msr;
- dom0_debug_t debug;
dom0_settime_t settime;
dom0_readconsole_t readconsole;
dom0_pincpudomain_t pincpudomain;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/grant_table.h
--- a/xen/include/public/grant_table.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/grant_table.h Wed Nov 30 19:55:08 2005
@@ -73,14 +73,14 @@
*/
typedef struct grant_entry {
/* GTF_xxx: various type and flag information. [XEN,GST] */
- uint16_t flags;
+ uint16_t flags;
/* The domain being granted foreign privileges. [GST] */
- domid_t domid;
+ domid_t domid;
/*
* GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
* GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
*/
- uint32_t frame;
+ uint32_t frame;
} grant_entry_t;
/*
@@ -131,7 +131,12 @@
/*
* Reference to a grant entry in a specified domain's grant table.
*/
-typedef uint16_t grant_ref_t;
+typedef uint32_t grant_ref_t;
+
+/*
+ * Handle to track a mapping created via a grant reference.
+ */
+typedef uint32_t grant_handle_t;
/*
* GNTTABOP_map_grant_ref: Map the grant entry (<dom>,<ref>) for access
@@ -154,11 +159,12 @@
typedef struct gnttab_map_grant_ref {
/* IN parameters. */
uint64_t host_addr;
+ uint32_t flags; /* GNTMAP_* */
+ grant_ref_t ref;
domid_t dom;
- grant_ref_t ref;
- uint16_t flags; /* GNTMAP_* */
- /* OUT parameters. */
- int16_t handle; /* +ve: handle; -ve: GNTST_* */
+ /* OUT parameters. */
+ int16_t status; /* GNTST_* */
+ grant_handle_t handle;
uint64_t dev_bus_addr;
} gnttab_map_grant_ref_t;
@@ -178,7 +184,7 @@
/* IN parameters. */
uint64_t host_addr;
uint64_t dev_bus_addr;
- uint16_t handle;
+ grant_handle_t handle;
/* OUT parameters. */
int16_t status; /* GNTST_* */
} gnttab_unmap_grant_ref_t;
@@ -196,7 +202,7 @@
typedef struct gnttab_setup_table {
/* IN parameters. */
domid_t dom;
- uint16_t nr_frames;
+ uint32_t nr_frames;
/* OUT parameters. */
int16_t status; /* GNTST_* */
unsigned long *frame_list;
@@ -283,7 +289,8 @@
"invalid virtual address", \
"invalid device address", \
"no spare translation slot in the I/O MMU", \
- "permission denied" \
+ "permission denied", \
+ "bad page" \
}
#endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/io/blkif.h
--- a/xen/include/public/io/blkif.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/io/blkif.h Wed Nov 30 19:55:08 2005
@@ -19,9 +19,6 @@
#define BLKIF_OP_READ 0
#define BLKIF_OP_WRITE 1
-/* NB. Ring size must be small enough for sizeof(blkif_ring_t) <= PAGE_SIZE. */
-#define BLKIF_RING_SIZE 64
-
/*
* Maximum scatter/gather segments per request.
* This is carefully chosen so that sizeof(blkif_ring_t) <= PAGE_SIZE.
@@ -33,33 +30,24 @@
uint8_t operation; /* BLKIF_OP_??? */
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
- unsigned long id; /* private guest value, echoed in resp */
+ uint64_t id; /* private guest value, echoed in resp */
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
- /* @f_a_s[4:0]=last_sect ; @f_a_s[9:5]=first_sect */
- /* @f_a_s[:16]= grant reference (16 bits) */
- /* @first_sect: first sector in frame to transfer (inclusive). */
- /* @last_sect: last sector in frame to transfer (inclusive). */
- unsigned long frame_and_sects[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+ struct blkif_request_segment {
+ grant_ref_t gref; /* reference to I/O buffer frame */
+ /* @first_sect: first sector in frame to transfer (inclusive). */
+ /* @last_sect: last sector in frame to transfer (inclusive). */
+ uint8_t first_sect, last_sect;
+ } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
} blkif_request_t;
-#define blkif_fas(_addr, _fs, _ls) ((_addr)|((_fs)<<5)|(_ls))
-#define blkif_first_sect(_fas) (((_fas)>>5)&31)
-#define blkif_last_sect(_fas) ((_fas)&31)
-
-#define blkif_fas_from_gref(_gref, _fs, _ls) (((_gref)<<16)|((_fs)<<5)|(_ls))
-#define blkif_gref_from_fas(_fas) ((_fas)>>16)
-
typedef struct blkif_response {
- unsigned long id; /* copied from request */
+ uint64_t id; /* copied from request */
uint8_t operation; /* copied from request */
int16_t status; /* BLKIF_RSP_??? */
} blkif_response_t;
#define BLKIF_RSP_ERROR -1 /* non-specific 'error' */
#define BLKIF_RSP_OKAY 0 /* non-specific 'okay' */
-
-#define BLKIF_MAJOR(dev) ((dev)>>8)
-#define BLKIF_MINOR(dev) ((dev) & 0xff)
/*
* Generate blkif ring structures and types.
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/io/tpmif.h
--- a/xen/include/public/io/tpmif.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/io/tpmif.h Wed Nov 30 19:55:08 2005
@@ -18,7 +18,7 @@
typedef struct {
unsigned long addr; /* Machine address of packet. */
- int ref; /* grant table access reference */
+ grant_ref_t ref; /* grant table access reference */
uint16_t id; /* Echoed in response message. */
uint16_t size; /* Packet size in bytes. */
} tpmif_tx_request_t;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/sched_ctl.h
--- a/xen/include/public/sched_ctl.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/sched_ctl.h Wed Nov 30 19:55:08 2005
@@ -48,8 +48,8 @@
uint64_t period;
uint64_t slice;
uint64_t latency;
- uint16_t extratime;
- uint16_t weight;
+ uint32_t extratime;
+ uint32_t weight;
} sedf;
} u;
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/xen.h
--- a/xen/include/public/xen.h Wed Nov 30 19:54:28 2005
+++ b/xen/include/public/xen.h Wed Nov 30 19:55:08 2005
@@ -410,9 +410,9 @@
unsigned long shared_info; /* MACHINE address of shared info struct. */
uint32_t flags; /* SIF_xxx flags. */
unsigned long store_mfn; /* MACHINE page number of shared page. */
- uint16_t store_evtchn; /* Event channel for store communication. */
+ uint32_t store_evtchn; /* Event channel for store communication. */
unsigned long console_mfn; /* MACHINE address of console page. */
- uint16_t console_evtchn; /* Event channel for console messages. */
+ uint32_t console_evtchn; /* Event channel for console messages. */
/* THE FOLLOWING ARE ONLY FILLED IN ON INITIAL BOOT (NOT RESUME). */
unsigned long pt_base; /* VIRTUAL address of page directory. */
unsigned long nr_pt_frames; /* Number of bootstrap p.t. frames. */
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/asm-x86/vmx_vpic.h
--- /dev/null Wed Nov 30 19:54:28 2005
+++ b/xen/include/asm-x86/vmx_vpic.h Wed Nov 30 19:55:08 2005
@@ -0,0 +1,85 @@
+/*
+ * QEMU System Emulator header
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ * Copyright (c) 2005 Intel Corp
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _VMX_VPIC_H
+#define _VMX_VPIC_H
+
+#define hw_error(x) do {} while (0);
+
+
+/* i8259.c */
+typedef struct IOAPICState IOAPICState;
+typedef struct PicState {
+ uint8_t last_irr; /* edge detection */
+ uint8_t irr; /* interrupt request register */
+ uint8_t imr; /* interrupt mask register */
+ uint8_t isr; /* interrupt service register */
+ uint8_t priority_add; /* highest irq priority */
+ uint8_t irq_base;
+ uint8_t read_reg_select;
+ uint8_t poll;
+ uint8_t special_mask;
+ uint8_t init_state;
+ uint8_t auto_eoi;
+ uint8_t rotate_on_auto_eoi;
+ uint8_t special_fully_nested_mode;
+ uint8_t init4; /* true if 4 byte init */
+ uint8_t elcr; /* PIIX edge/trigger selection*/
+ uint8_t elcr_mask;
+ struct vmx_virpic *pics_state;
+} PicState;
+
+struct vmx_virpic {
+ /* 0 is master pic, 1 is slave pic */
+ /* XXX: better separation between the two pics */
+ PicState pics[2];
+ void (*irq_request)(int *opaque, int level);
+ void *irq_request_opaque;
+ /* IOAPIC callback support */
+ void (*alt_irq_func)(void *opaque, int irq_num, int level);
+ void *alt_irq_opaque;
+};
+
+
+void pic_set_irq(struct vmx_virpic *s, int irq, int level);
+void pic_set_irq_new(void *opaque, int irq, int level);
+void pic_init(struct vmx_virpic *s,
+ void (*irq_request)(),
+ void *irq_request_opaque);
+void pic_set_alt_irq_func(struct vmx_virpic *s,
+ void(*alt_irq_func)(),
+ void *alt_irq_opaque);
+int pic_read_irq(struct vmx_virpic *s);
+void pic_update_irq(struct vmx_virpic *s);
+uint32_t pic_intack_read(struct vmx_virpic *s);
+void register_pic_io_hook (void);
+int cpu_get_pic_interrupt(struct vcpu *v, int *type);
+int is_pit_irq(struct vcpu *v, int irq, int type);
+int is_irq_enabled(struct vcpu *v, int irq);
+void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
+void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
+
+/* APIC */
+#endif /* _VMX_VPIC_H */
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/asm-x86/vmx_vpit.h
--- /dev/null Wed Nov 30 19:54:28 2005
+++ b/xen/include/asm-x86/vmx_vpit.h Wed Nov 30 19:55:08 2005
@@ -0,0 +1,55 @@
+#ifndef _VMX_VIRPIT_H
+#define _VMX_VIRPIT_H
+
+#include <xen/config.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/time.h>
+#include <xen/errno.h>
+#include <xen/ac_timer.h>
+#include <asm/vmx_vmcs.h>
+#include <asm/vmx_vpic.h>
+
+#define PIT_FREQ 1193181
+
+#define LSByte 0
+#define MSByte 1
+#define LSByte_multiple 2
+#define MSByte_multiple 3
+
+struct vmx_virpit {
+ /* for simulation of counter 0 in mode 2*/
+ u64 period_cycles; /* pit frequency in cpu cycles */
+ u64 inject_point; /* the time inject virt intr */
+ s_time_t scheduled; /* scheduled timer interrupt */
+ struct ac_timer pit_timer; /* periodic timer for mode 2*/
+ unsigned int channel; /* the pit channel, counter 0~2 */
+ unsigned int pending_intr_nr; /* the couner for pending timer interrupts */
+ u32 period; /* pit frequency in ns */
+ int first_injected; /* flag to prevent shadow window */
+ int ticking; /* indicating it is ticking */
+
+ /* virtual PIT state for handle related I/O */
+ int read_state;
+ int count_LSB_latched;
+ int count_MSB_latched;
+
+ unsigned int count; /* the 16 bit channel count */
+ unsigned int init_val; /* the init value for the counter */
+};
+
+/* to hook the ioreq packet to get the PIT initializaiton info */
+extern void vmx_hooks_assist(struct vcpu *v);
+
+static __inline__ s_time_t get_pit_scheduled(
+ struct vcpu *v,
+ struct vmx_virpit *vpit)
+{
+ if ( is_irq_enabled(v, 0) ) {
+ return vpit->scheduled;
+ }
+ else
+ return -1;
+}
+
+#endif /* _VMX_VIRPIT_H_ */
diff -r 6a2acc1cc505 -r 28ce48573771 tools/vtpm_manager/util/depend
--- a/tools/vtpm_manager/util/depend Wed Nov 30 19:54:28 2005
+++ /dev/null Wed Nov 30 19:55:08 2005
@@ -1,7 +0,0 @@
-hashtable.o: hashtable.c hashtable.h hashtable_private.h
-hashtable_itr.o: hashtable_itr.c hashtable.h hashtable_private.h \
- hashtable_itr.h
-bsg.o: bsg.c tcg.h ../crypto/crypto.h ../crypto/sym_crypto.h buffer.h \
- bsg.h log.h
-log.o: log.c buffer.h tcg.h
-buffer.o: buffer.c tcg.h bsg.h buffer.h
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/asm-x86/vmx_virpit.h
--- a/xen/include/asm-x86/vmx_virpit.h Wed Nov 30 19:54:28 2005
+++ /dev/null Wed Nov 30 19:55:08 2005
@@ -1,55 +0,0 @@
-#ifndef _VMX_VIRPIT_H
-#define _VMX_VIRPIT_H
-
-#include <xen/config.h>
-#include <xen/init.h>
-#include <xen/lib.h>
-#include <xen/time.h>
-#include <xen/errno.h>
-#include <xen/ac_timer.h>
-#include <asm/vmx_vmcs.h>
-#include <public/io/vmx_vpic.h>
-
-#define PIT_FREQ 1193181
-
-#define LSByte 0
-#define MSByte 1
-#define LSByte_multiple 2
-#define MSByte_multiple 3
-
-struct vmx_virpit {
- /* for simulation of counter 0 in mode 2*/
- u64 period_cycles; /* pit frequency in cpu cycles */
- u64 inject_point; /* the time inject virt intr */
- s_time_t scheduled; /* scheduled timer interrupt */
- struct ac_timer pit_timer; /* periodic timer for mode 2*/
- unsigned int channel; /* the pit channel, counter 0~2 */
- unsigned int pending_intr_nr; /* the couner for pending timer interrupts */
- u32 period; /* pit frequency in ns */
- int first_injected; /* flag to prevent shadow window */
- int ticking; /* indicating it is ticking */
-
- /* virtual PIT state for handle related I/O */
- int read_state;
- int count_LSB_latched;
- int count_MSB_latched;
-
- unsigned int count; /* the 16 bit channel count */
- unsigned int init_val; /* the init value for the counter */
-};
-
-/* to hook the ioreq packet to get the PIT initializaiton info */
-extern void vmx_hooks_assist(struct vcpu *v);
-
-static __inline__ s_time_t get_pit_scheduled(
- struct vcpu *v,
- struct vmx_virpit *vpit)
-{
- if ( is_irq_enabled(v, 0) ) {
- return vpit->scheduled;
- }
- else
- return -1;
-}
-
-#endif /* _VMX_VIRPIT_H_ */
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/io/vmx_vlapic.h
--- a/xen/include/public/io/vmx_vlapic.h Wed Nov 30 19:54:28 2005
+++ /dev/null Wed Nov 30 19:55:08 2005
@@ -1,58 +0,0 @@
-#ifndef _VMX_VLAPIC_H
-#define _VMX_VLAPIC_H
-
-/*
- We extended one bit for PIC type
- */
-#define VLAPIC_DELIV_MODE_FIXED 0x0
-#define VLAPIC_DELIV_MODE_LPRI 0x1
-#define VLAPIC_DELIV_MODE_SMI 0x2
-#define VLAPIC_DELIV_MODE_NMI 0x4
-#define VLAPIC_DELIV_MODE_INIT 0x5
-#define VLAPIC_DELIV_MODE_STARTUP 0x6
-#define VLAPIC_DELIV_MODE_EXT 0x7
-#define VLAPIC_DELIV_MODE_MASK 0x8
-
-#define VLAPIC_MSG_LEVEL 4
-
-#define INTR_EXT 0
-#define INTR_APIC 1
-#define INTR_LAPIC 2
-
-#define VL_STATE_EOI 1
-#define VL_STATE_EXT_LOCK 2
-#define VL_STATE_MSG_LOCK 3
-#define VL_STATE_EOI_LOCK 3
-
-#define VLOCAL_APIC_MAX_INTS 256
-#define VLAPIC_INT_COUNT (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE *
sizeof(uint64_t)))
-#define VLAPIC_INT_COUNT_32 (VLOCAL_APIC_MAX_INTS/(BITS_PER_BYTE *
sizeof(uint32_t)))
-
-typedef struct {
- /* interrupt for PIC and ext type IOAPIC interrupt */
- uint64_t vl_ext_intr[VLAPIC_INT_COUNT];
- uint64_t vl_ext_intr_mask[VLAPIC_INT_COUNT];
- uint64_t vl_apic_intr[VLAPIC_INT_COUNT];
- uint64_t vl_apic_tmr[VLAPIC_INT_COUNT];
- uint64_t vl_eoi[VLAPIC_INT_COUNT];
- uint32_t vl_lapic_id;
- uint32_t direct_intr;
- uint32_t vl_apr;
- uint32_t vl_logical_dest;
- uint32_t vl_dest_format;
- uint32_t vl_arb_id;
- uint32_t vl_state;
- uint32_t apic_msg_count;
-} vlapic_info;
-
-#endif /* _VMX_VLAPIC_H_ */
-
-/*
- * Local variables:
- * mode: C
- * c-set-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff -r 6a2acc1cc505 -r 28ce48573771 xen/include/public/io/vmx_vpic.h
--- a/xen/include/public/io/vmx_vpic.h Wed Nov 30 19:54:28 2005
+++ /dev/null Wed Nov 30 19:55:08 2005
@@ -1,85 +0,0 @@
-/*
- * QEMU System Emulator header
- *
- * Copyright (c) 2003 Fabrice Bellard
- * Copyright (c) 2005 Intel Corp
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef _VMX_VPIC_H
-#define _VMX_VPIC_H
-
-#define hw_error(x) do {} while (0);
-
-
-/* i8259.c */
-typedef struct IOAPICState IOAPICState;
-typedef struct PicState {
- uint8_t last_irr; /* edge detection */
- uint8_t irr; /* interrupt request register */
- uint8_t imr; /* interrupt mask register */
- uint8_t isr; /* interrupt service register */
- uint8_t priority_add; /* highest irq priority */
- uint8_t irq_base;
- uint8_t read_reg_select;
- uint8_t poll;
- uint8_t special_mask;
- uint8_t init_state;
- uint8_t auto_eoi;
- uint8_t rotate_on_auto_eoi;
- uint8_t special_fully_nested_mode;
- uint8_t init4; /* true if 4 byte init */
- uint8_t elcr; /* PIIX edge/trigger selection*/
- uint8_t elcr_mask;
- struct vmx_virpic *pics_state;
-} PicState;
-
-struct vmx_virpic {
- /* 0 is master pic, 1 is slave pic */
- /* XXX: better separation between the two pics */
- PicState pics[2];
- void (*irq_request)(int *opaque, int level);
- void *irq_request_opaque;
- /* IOAPIC callback support */
- void (*alt_irq_func)(void *opaque, int irq_num, int level);
- void *alt_irq_opaque;
-};
-
-
-void pic_set_irq(struct vmx_virpic *s, int irq, int level);
-void pic_set_irq_new(void *opaque, int irq, int level);
-void pic_init(struct vmx_virpic *s,
- void (*irq_request)(),
- void *irq_request_opaque);
-void pic_set_alt_irq_func(struct vmx_virpic *s,
- void(*alt_irq_func)(),
- void *alt_irq_opaque);
-int pic_read_irq(struct vmx_virpic *s);
-void pic_update_irq(struct vmx_virpic *s);
-uint32_t pic_intack_read(struct vmx_virpic *s);
-void register_pic_io_hook (void);
-int cpu_get_pic_interrupt(struct vcpu *v, int *type);
-int is_pit_irq(struct vcpu *v, int irq, int type);
-int is_irq_enabled(struct vcpu *v, int irq);
-void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
-void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
-
-/* APIC */
-#endif /* _VMX_VPIC_H */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|