WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Some cleanup in tpm-related files.

# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 7a45b8ccef01803a6f4b3c265e149862d9e00a2d
# Parent  b8537442f3d6ef953bc7b0bd2b69c674e0038caf
Some cleanup in tpm-related files.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>

diff -r b8537442f3d6 -r 7a45b8ccef01 linux-2.6-xen-sparse/arch/xen/Kconfig
--- a/linux-2.6-xen-sparse/arch/xen/Kconfig     Wed Sep 21 10:11:02 2005
+++ b/linux-2.6-xen-sparse/arch/xen/Kconfig     Wed Sep 21 10:13:11 2005
@@ -73,6 +73,8 @@
 config XEN_TPMDEV_FRONTEND
         bool "TPM-device frontend driver"
         default n
+       select TCG_TPM
+       select TCG_XEN
         help
           The TPM-device frontend driver.
 
diff -r b8537442f3d6 -r 7a45b8ccef01 
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Wed Sep 21 
10:11:02 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c      Wed Sep 21 
10:13:11 2005
@@ -1,4 +1,4 @@
-/******************************************************************************
+ 
/******************************************************************************
  * drivers/xen/tpmback/interface.c
  *
  * Vritual TPM interface management.
@@ -21,180 +21,175 @@
 
 static kmem_cache_t *tpmif_cachep;
 int num_frontends = 0;
+
 LIST_HEAD(tpmif_list);
 
+tpmif_t *
+alloc_tpmif(domid_t domid, long int instance)
+{
+       struct page *page;
+       tpmif_t *tpmif;
 
-tpmif_t *alloc_tpmif(domid_t domid, long int instance)
-{
-    struct page *page;
-    tpmif_t *tpmif;
+       tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
+       if (!tpmif)
+               return ERR_PTR(-ENOMEM);
 
-    tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
-    if (!tpmif)
-        return ERR_PTR(-ENOMEM);
+       memset(tpmif, 0, sizeof (*tpmif));
+       tpmif->domid = domid;
+       tpmif->status = DISCONNECTED;
+       tpmif->tpm_instance = instance;
+       atomic_set(&tpmif->refcnt, 1);
 
-    memset(tpmif, 0, sizeof(*tpmif));
-    tpmif->domid        = domid;
-    tpmif->status       = DISCONNECTED;
-    tpmif->tpm_instance = instance;
-    atomic_set(&tpmif->refcnt, 1);
+       page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
+       BUG_ON(page == NULL);
+       tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
 
-    page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
-    BUG_ON(page == NULL);
-    tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
+       list_add(&tpmif->tpmif_list, &tpmif_list);
+       num_frontends++;
 
-    list_add(&tpmif->tpmif_list, &tpmif_list);
-    num_frontends++;
-
-    return tpmif;
+       return tpmif;
 }
 
-
-void free_tpmif(tpmif_t *tpmif)
+void
+free_tpmif(tpmif_t * tpmif)
 {
-    num_frontends--;
-    list_del(&tpmif->tpmif_list);
-    kmem_cache_free(tpmif_cachep, tpmif);
+       num_frontends--;
+       list_del(&tpmif->tpmif_list);
+       kmem_cache_free(tpmif_cachep, tpmif);
 }
 
+tpmif_t *
+tpmif_find(domid_t domid, long int instance)
+{
+       tpmif_t *tpmif;
 
-tpmif_t *tpmif_find(domid_t domid, long int instance)
-{
-    tpmif_t *tpmif;
+       list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
+               if (tpmif->tpm_instance == instance) {
+                       if (tpmif->domid == domid) {
+                               tpmif_get(tpmif);
+                               return tpmif;
+                       } else {
+                               return NULL;
+                       }
+               }
+       }
 
-    list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
-        if (tpmif->tpm_instance == instance) {
-            if (tpmif->domid == domid) {
-                tpmif_get(tpmif);
-                return tpmif;
-           } else {
-               return NULL;
-           }
-        }
-    }
-
-    return alloc_tpmif(domid, instance);
+       return alloc_tpmif(domid, instance);
 }
 
+static int
+map_frontend_page(tpmif_t * tpmif, unsigned long localaddr,
+                 unsigned long shared_page)
+{
+       struct gnttab_map_grant_ref op = {
+               .host_addr = localaddr,
+               .flags = GNTMAP_host_map,
+               .ref = shared_page,
+               .dom = tpmif->domid,
+       };
 
-static int map_frontend_page(tpmif_t *tpmif, unsigned long localaddr,
-                            unsigned long shared_page)
-{
-    struct gnttab_map_grant_ref op = {
-        .host_addr = localaddr,
-        .flags     = GNTMAP_host_map,
-        .ref       = shared_page,
-        .dom       = tpmif->domid,
-    };
+       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
 
-    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
+       if (op.handle < 0) {
+               DPRINTK(" Grant table operation failure !\n");
+               return op.handle;
+       }
 
-    if (op.handle < 0) {
-       DPRINTK(" Grant table operation failure !\n");
-       return op.handle;
-    }
-
-    tpmif->shmem_ref    = shared_page;
-    tpmif->shmem_handle = op.handle;
-    tpmif->shmem_vaddr  = localaddr;
-    return 0;
+       tpmif->shmem_ref = shared_page;
+       tpmif->shmem_handle = op.handle;
+       tpmif->shmem_vaddr = localaddr;
+       return 0;
 }
 
+static void
+unmap_frontend_page(tpmif_t * tpmif)
+{
+       struct gnttab_unmap_grant_ref op;
 
-static void unmap_frontend_page(tpmif_t *tpmif)
-{
-    struct gnttab_unmap_grant_ref op;
+       op.host_addr = tpmif->shmem_vaddr;
+       op.handle = tpmif->shmem_handle;
+       op.dev_bus_addr = 0;
 
-    op.host_addr = tpmif->shmem_vaddr;
-    op.handle = tpmif->shmem_handle;
-    op.dev_bus_addr = 0;
-
-    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
+       BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
 }
 
+int
+tpmif_map(tpmif_t * tpmif, unsigned long shared_page, unsigned int evtchn)
+{
+       struct vm_struct *vma;
+       evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
+       int err;
 
-int tpmif_map(tpmif_t *tpmif,
-              unsigned long shared_page, unsigned int evtchn)
-{
-    struct vm_struct *vma;
-    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
-    int err;
+       BUG_ON(tpmif->remote_evtchn);
 
-    BUG_ON(tpmif->remote_evtchn);
+       if ((vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL)
+               return -ENOMEM;
 
-    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
-       return -ENOMEM;
+       err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
+       if (err) {
+               vfree(vma->addr);
+               return err;
+       }
 
-    err = map_frontend_page(tpmif,
-                            VMALLOC_VMADDR(vma->addr),
-                            shared_page);
-    if (err) {
-        vfree(vma->addr);
-       return err;
-    }
+       op.u.bind_interdomain.dom1 = DOMID_SELF;
+       op.u.bind_interdomain.dom2 = tpmif->domid;
+       op.u.bind_interdomain.port1 = 0;
+       op.u.bind_interdomain.port2 = evtchn;
+       err = HYPERVISOR_event_channel_op(&op);
+       if (err) {
+               unmap_frontend_page(tpmif);
+               vfree(vma->addr);
+               return err;
+       }
 
-    op.u.bind_interdomain.dom1 = DOMID_SELF;
-    op.u.bind_interdomain.dom2 = tpmif->domid;
-    op.u.bind_interdomain.port1 = 0;
-    op.u.bind_interdomain.port2 = evtchn;
-    err = HYPERVISOR_event_channel_op(&op);
-    if (err) {
-       unmap_frontend_page(tpmif);
-       vfree(vma->addr);
-       return err;
-    }
+       tpmif->evtchn = op.u.bind_interdomain.port1;
+       tpmif->remote_evtchn = evtchn;
 
-    tpmif->evtchn = op.u.bind_interdomain.port1;
-    tpmif->remote_evtchn = evtchn;
+       tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
 
-    tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
+       bind_evtchn_to_irqhandler(tpmif->evtchn,
+                                 tpmif_be_int, 0, "tpmif-backend", tpmif);
+       tpmif->status = CONNECTED;
+       tpmif->shmem_ref = shared_page;
+       tpmif->active = 1;
 
-    bind_evtchn_to_irqhandler(tpmif->evtchn,
-                              tpmif_be_int,
-                              0,
-                              "tpmif-backend",
-                             tpmif);
-    tpmif->status        = CONNECTED;
-    tpmif->shmem_ref     = shared_page;
-    tpmif->active        = 1;
-
-    return 0;
+       return 0;
 }
 
+static void
+__tpmif_disconnect_complete(void *arg)
+{
+       evtchn_op_t op = {.cmd = EVTCHNOP_close };
+       tpmif_t *tpmif = (tpmif_t *) arg;
 
-static void __tpmif_disconnect_complete(void *arg)
-{
-    evtchn_op_t op = { .cmd = EVTCHNOP_close };
-    tpmif_t *tpmif = (tpmif_t *) arg;
+       op.u.close.port = tpmif->evtchn;
+       op.u.close.dom = DOMID_SELF;
+       HYPERVISOR_event_channel_op(&op);
+       op.u.close.port = tpmif->remote_evtchn;
+       op.u.close.dom = tpmif->domid;
+       HYPERVISOR_event_channel_op(&op);
 
-    op.u.close.port = tpmif->evtchn;
-    op.u.close.dom  = DOMID_SELF;
-    HYPERVISOR_event_channel_op(&op);
-    op.u.close.port = tpmif->remote_evtchn;
-    op.u.close.dom  = tpmif->domid;
-    HYPERVISOR_event_channel_op(&op);
+       if (tpmif->evtchn)
+               unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
 
-    if (tpmif->evtchn)
-         unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
+       if (tpmif->tx) {
+               unmap_frontend_page(tpmif);
+               vfree(tpmif->tx);
+       }
 
-    if (tpmif->tx) {
-        unmap_frontend_page(tpmif);
-        vfree(tpmif->tx);
-    }
-
-    free_tpmif(tpmif);
+       free_tpmif(tpmif);
 }
 
-
-void tpmif_disconnect_complete(tpmif_t * tpmif)
+void
+tpmif_disconnect_complete(tpmif_t * tpmif)
 {
-    INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
-    schedule_work(&tpmif->work);
+       INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
+       schedule_work(&tpmif->work);
 }
 
-
-void __init tpmif_interface_init(void)
+void __init
+tpmif_interface_init(void)
 {
-    tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof(tpmif_t),
-                                     0, 0, NULL, NULL);
+       tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
+                                        0, 0, NULL, NULL);
 }
diff -r b8537442f3d6 -r 7a45b8ccef01 
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Wed Sep 21 
10:11:02 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Wed Sep 21 
10:13:11 2005
@@ -257,18 +257,24 @@
 
        tpm_allocate_buffers(tp);
 
-       info->ring_ref = gnttab_claim_grant_reference(&gref_head);
-       ASSERT(info->ring_ref != -ENOSPC);
-       gnttab_grant_foreign_access_ref(info->ring_ref,
-                                       backend_id,
-                                       (virt_to_machine(tp->tx) >> PAGE_SHIFT),
-                                       0);
+       err = gnttab_grant_foreign_access(backend_id,
+                                         (virt_to_machine(tp->tx) >> 
PAGE_SHIFT),
+                                         0);
+
+       if (err == -ENOSPC) {
+               free_page((unsigned long)sring);
+               tp->tx = NULL;
+               xenbus_dev_error(dev, err, "allocating grant reference");
+               return err;
+       }
+       info->ring_ref = err;
 
        op.u.alloc_unbound.dom = backend_id;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
+               gnttab_end_foreign_access(info->ring_ref, 0);
                free_page((unsigned long)sring);
-               tp->tx = 0;
+               tp->tx = NULL;
                xenbus_dev_error(dev, err, "allocating event channel");
                return err;
        }
@@ -282,6 +288,7 @@
        tpmif_set_connected_state(tp,0);
 
        if ( tp->tx != NULL ) {
+               gnttab_end_foreign_access(info->ring_ref, 0);
                free_page((unsigned long)tp->tx);
                tp->tx = NULL;
        }
diff -r b8537442f3d6 -r 7a45b8ccef01 
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h
--- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h      Wed Sep 21 
10:11:02 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h      Wed Sep 21 
10:13:11 2005
@@ -2,7 +2,8 @@
 #define TPM_FRONT_H
 
 
-struct tpm_private {
+struct tpm_private
+{
        tpmif_tx_interface_t *tx;
        unsigned int evtchn;
        int connected;
@@ -29,7 +30,8 @@
 };
 
 
-struct tx_buffer {
+struct tx_buffer
+{
        unsigned int size;      // available space in data
        unsigned int len;       // used space in data
        unsigned char *data;    // pointer to a page
diff -r b8537442f3d6 -r 7a45b8ccef01 tools/python/xen/xend/server/tpmif.py
--- a/tools/python/xen/xend/server/tpmif.py     Wed Sep 21 10:11:02 2005
+++ b/tools/python/xen/xend/server/tpmif.py     Wed Sep 21 10:13:11 2005
@@ -39,7 +39,7 @@
         """@see DevController.getDeviceDetails"""
         
         devid = int(sxp.child_value(config, 'instance', '0'))
-        log.error("The domain has a TPM with instance %d." % devid)
+        log.debug("The domain has a TPM with instance %d." % devid)
 
         back  = { 'instance' : "%i" % devid }
         front = { 'handle' : "%i" % devid }
diff -r b8537442f3d6 -r 7a45b8ccef01 xen/include/public/io/tpmif.h
--- a/xen/include/public/io/tpmif.h     Wed Sep 21 10:11:02 2005
+++ b/xen/include/public/io/tpmif.h     Wed Sep 21 10:13:11 2005
@@ -20,8 +20,7 @@
     unsigned long addr;   /* Machine address of packet.   */
     int      ref;         /* grant table access reference */
     u16      id;          /* Echoed in response message.  */
-    u16      size:15;     /* Packet size in bytes.        */
-    u16      mapped:1;
+    u16      size;        /* Packet size in bytes.        */
 } tpmif_tx_request_t;
 
 /*
@@ -30,13 +29,16 @@
  */
 typedef u32 TPMIF_RING_IDX;
 
-#define TPMIF_TX_RING_SIZE 16
+#define TPMIF_TX_RING_SIZE 10
 
 /* This structure must fit in a memory page. */
+
 typedef struct {
-    union {
-        tpmif_tx_request_t  req;
-    } ring[TPMIF_TX_RING_SIZE];
+    tpmif_tx_request_t req;
+} tpmif_ring_t;
+
+typedef struct {
+    tpmif_ring_t ring[TPMIF_TX_RING_SIZE];
 } tpmif_tx_interface_t;
 
 #endif

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Some cleanup in tpm-related files., Xen patchbot -unstable <=