ia64/xen-unstable

changeset 6989:7a45b8ccef01

Some cleanup in tpm-related files.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Sep 21 10:13:11 2005 +0000 (2005-09-21)
parents b8537442f3d6
children 55fc0ecc19c3
files linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h tools/python/xen/xend/server/tpmif.py xen/include/public/io/tpmif.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 10:11:02 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 10:13:11 2005 +0000
     1.3 @@ -73,6 +73,8 @@ config XEN_NETDEV_BACKEND
     1.4  config XEN_TPMDEV_FRONTEND
     1.5          bool "TPM-device frontend driver"
     1.6          default n
     1.7 +	select TCG_TPM
     1.8 +	select TCG_XEN
     1.9          help
    1.10            The TPM-device frontend driver.
    1.11  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 10:11:02 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 10:13:11 2005 +0000
     2.3 @@ -1,4 +1,4 @@
     2.4 -/******************************************************************************
     2.5 + /******************************************************************************
     2.6   * drivers/xen/tpmback/interface.c
     2.7   *
     2.8   * Vritual TPM interface management.
     2.9 @@ -21,180 +21,175 @@
    2.10  
    2.11  static kmem_cache_t *tpmif_cachep;
    2.12  int num_frontends = 0;
    2.13 +
    2.14  LIST_HEAD(tpmif_list);
    2.15  
    2.16 -
    2.17 -tpmif_t *alloc_tpmif(domid_t domid, long int instance)
    2.18 +tpmif_t *
    2.19 +alloc_tpmif(domid_t domid, long int instance)
    2.20  {
    2.21 -    struct page *page;
    2.22 -    tpmif_t *tpmif;
    2.23 +	struct page *page;
    2.24 +	tpmif_t *tpmif;
    2.25  
    2.26 -    tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    2.27 -    if (!tpmif)
    2.28 -        return ERR_PTR(-ENOMEM);
    2.29 +	tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    2.30 +	if (!tpmif)
    2.31 +		return ERR_PTR(-ENOMEM);
    2.32  
    2.33 -    memset(tpmif, 0, sizeof(*tpmif));
    2.34 -    tpmif->domid        = domid;
    2.35 -    tpmif->status       = DISCONNECTED;
    2.36 -    tpmif->tpm_instance = instance;
    2.37 -    atomic_set(&tpmif->refcnt, 1);
    2.38 +	memset(tpmif, 0, sizeof (*tpmif));
    2.39 +	tpmif->domid = domid;
    2.40 +	tpmif->status = DISCONNECTED;
    2.41 +	tpmif->tpm_instance = instance;
    2.42 +	atomic_set(&tpmif->refcnt, 1);
    2.43  
    2.44 -    page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    2.45 -    BUG_ON(page == NULL);
    2.46 -    tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    2.47 +	page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    2.48 +	BUG_ON(page == NULL);
    2.49 +	tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    2.50  
    2.51 -    list_add(&tpmif->tpmif_list, &tpmif_list);
    2.52 -    num_frontends++;
    2.53 +	list_add(&tpmif->tpmif_list, &tpmif_list);
    2.54 +	num_frontends++;
    2.55  
    2.56 -    return tpmif;
    2.57 +	return tpmif;
    2.58  }
    2.59  
    2.60 -
    2.61 -void free_tpmif(tpmif_t *tpmif)
    2.62 +void
    2.63 +free_tpmif(tpmif_t * tpmif)
    2.64  {
    2.65 -    num_frontends--;
    2.66 -    list_del(&tpmif->tpmif_list);
    2.67 -    kmem_cache_free(tpmif_cachep, tpmif);
    2.68 +	num_frontends--;
    2.69 +	list_del(&tpmif->tpmif_list);
    2.70 +	kmem_cache_free(tpmif_cachep, tpmif);
    2.71  }
    2.72  
    2.73 -
    2.74 -tpmif_t *tpmif_find(domid_t domid, long int instance)
    2.75 +tpmif_t *
    2.76 +tpmif_find(domid_t domid, long int instance)
    2.77  {
    2.78 -    tpmif_t *tpmif;
    2.79 +	tpmif_t *tpmif;
    2.80  
    2.81 -    list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    2.82 -        if (tpmif->tpm_instance == instance) {
    2.83 -            if (tpmif->domid == domid) {
    2.84 -                tpmif_get(tpmif);
    2.85 -                return tpmif;
    2.86 -	    } else {
    2.87 -	        return NULL;
    2.88 -	    }
    2.89 -        }
    2.90 -    }
    2.91 +	list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    2.92 +		if (tpmif->tpm_instance == instance) {
    2.93 +			if (tpmif->domid == domid) {
    2.94 +				tpmif_get(tpmif);
    2.95 +				return tpmif;
    2.96 +			} else {
    2.97 +				return NULL;
    2.98 +			}
    2.99 +		}
   2.100 +	}
   2.101  
   2.102 -    return alloc_tpmif(domid, instance);
   2.103 +	return alloc_tpmif(domid, instance);
   2.104  }
   2.105  
   2.106 -
   2.107 -static int map_frontend_page(tpmif_t *tpmif, unsigned long localaddr,
   2.108 -			     unsigned long shared_page)
   2.109 +static int
   2.110 +map_frontend_page(tpmif_t * tpmif, unsigned long localaddr,
   2.111 +		  unsigned long shared_page)
   2.112  {
   2.113 -    struct gnttab_map_grant_ref op = {
   2.114 -        .host_addr = localaddr,
   2.115 -        .flags     = GNTMAP_host_map,
   2.116 -        .ref       = shared_page,
   2.117 -        .dom       = tpmif->domid,
   2.118 -    };
   2.119 +	struct gnttab_map_grant_ref op = {
   2.120 +		.host_addr = localaddr,
   2.121 +		.flags = GNTMAP_host_map,
   2.122 +		.ref = shared_page,
   2.123 +		.dom = tpmif->domid,
   2.124 +	};
   2.125  
   2.126 -    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   2.127 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   2.128  
   2.129 -    if (op.handle < 0) {
   2.130 -	DPRINTK(" Grant table operation failure !\n");
   2.131 -	return op.handle;
   2.132 -    }
   2.133 +	if (op.handle < 0) {
   2.134 +		DPRINTK(" Grant table operation failure !\n");
   2.135 +		return op.handle;
   2.136 +	}
   2.137  
   2.138 -    tpmif->shmem_ref    = shared_page;
   2.139 -    tpmif->shmem_handle = op.handle;
   2.140 -    tpmif->shmem_vaddr  = localaddr;
   2.141 -    return 0;
   2.142 +	tpmif->shmem_ref = shared_page;
   2.143 +	tpmif->shmem_handle = op.handle;
   2.144 +	tpmif->shmem_vaddr = localaddr;
   2.145 +	return 0;
   2.146  }
   2.147  
   2.148 -
   2.149 -static void unmap_frontend_page(tpmif_t *tpmif)
   2.150 +static void
   2.151 +unmap_frontend_page(tpmif_t * tpmif)
   2.152  {
   2.153 -    struct gnttab_unmap_grant_ref op;
   2.154 +	struct gnttab_unmap_grant_ref op;
   2.155  
   2.156 -    op.host_addr = tpmif->shmem_vaddr;
   2.157 -    op.handle = tpmif->shmem_handle;
   2.158 -    op.dev_bus_addr = 0;
   2.159 +	op.host_addr = tpmif->shmem_vaddr;
   2.160 +	op.handle = tpmif->shmem_handle;
   2.161 +	op.dev_bus_addr = 0;
   2.162  
   2.163 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   2.164 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   2.165  }
   2.166  
   2.167 -
   2.168 -int tpmif_map(tpmif_t *tpmif,
   2.169 -              unsigned long shared_page, unsigned int evtchn)
   2.170 +int
   2.171 +tpmif_map(tpmif_t * tpmif, unsigned long shared_page, unsigned int evtchn)
   2.172  {
   2.173 -    struct vm_struct *vma;
   2.174 -    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   2.175 -    int err;
   2.176 +	struct vm_struct *vma;
   2.177 +	evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
   2.178 +	int err;
   2.179  
   2.180 -    BUG_ON(tpmif->remote_evtchn);
   2.181 +	BUG_ON(tpmif->remote_evtchn);
   2.182  
   2.183 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
   2.184 -	return -ENOMEM;
   2.185 +	if ((vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL)
   2.186 +		return -ENOMEM;
   2.187  
   2.188 -    err = map_frontend_page(tpmif,
   2.189 -                            VMALLOC_VMADDR(vma->addr),
   2.190 -                            shared_page);
   2.191 -    if (err) {
   2.192 -        vfree(vma->addr);
   2.193 -	return err;
   2.194 -    }
   2.195 +	err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
   2.196 +	if (err) {
   2.197 +		vfree(vma->addr);
   2.198 +		return err;
   2.199 +	}
   2.200  
   2.201 -    op.u.bind_interdomain.dom1 = DOMID_SELF;
   2.202 -    op.u.bind_interdomain.dom2 = tpmif->domid;
   2.203 -    op.u.bind_interdomain.port1 = 0;
   2.204 -    op.u.bind_interdomain.port2 = evtchn;
   2.205 -    err = HYPERVISOR_event_channel_op(&op);
   2.206 -    if (err) {
   2.207 -	unmap_frontend_page(tpmif);
   2.208 -	vfree(vma->addr);
   2.209 -	return err;
   2.210 -    }
   2.211 +	op.u.bind_interdomain.dom1 = DOMID_SELF;
   2.212 +	op.u.bind_interdomain.dom2 = tpmif->domid;
   2.213 +	op.u.bind_interdomain.port1 = 0;
   2.214 +	op.u.bind_interdomain.port2 = evtchn;
   2.215 +	err = HYPERVISOR_event_channel_op(&op);
   2.216 +	if (err) {
   2.217 +		unmap_frontend_page(tpmif);
   2.218 +		vfree(vma->addr);
   2.219 +		return err;
   2.220 +	}
   2.221  
   2.222 -    tpmif->evtchn = op.u.bind_interdomain.port1;
   2.223 -    tpmif->remote_evtchn = evtchn;
   2.224 +	tpmif->evtchn = op.u.bind_interdomain.port1;
   2.225 +	tpmif->remote_evtchn = evtchn;
   2.226  
   2.227 -    tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   2.228 +	tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   2.229  
   2.230 -    bind_evtchn_to_irqhandler(tpmif->evtchn,
   2.231 -                              tpmif_be_int,
   2.232 -                              0,
   2.233 -                              "tpmif-backend",
   2.234 -			      tpmif);
   2.235 -    tpmif->status        = CONNECTED;
   2.236 -    tpmif->shmem_ref     = shared_page;
   2.237 -    tpmif->active        = 1;
   2.238 +	bind_evtchn_to_irqhandler(tpmif->evtchn,
   2.239 +				  tpmif_be_int, 0, "tpmif-backend", tpmif);
   2.240 +	tpmif->status = CONNECTED;
   2.241 +	tpmif->shmem_ref = shared_page;
   2.242 +	tpmif->active = 1;
   2.243  
   2.244 -    return 0;
   2.245 +	return 0;
   2.246  }
   2.247  
   2.248 -
   2.249 -static void __tpmif_disconnect_complete(void *arg)
   2.250 +static void
   2.251 +__tpmif_disconnect_complete(void *arg)
   2.252  {
   2.253 -    evtchn_op_t op = { .cmd = EVTCHNOP_close };
   2.254 -    tpmif_t *tpmif = (tpmif_t *) arg;
   2.255 +	evtchn_op_t op = {.cmd = EVTCHNOP_close };
   2.256 +	tpmif_t *tpmif = (tpmif_t *) arg;
   2.257  
   2.258 -    op.u.close.port = tpmif->evtchn;
   2.259 -    op.u.close.dom  = DOMID_SELF;
   2.260 -    HYPERVISOR_event_channel_op(&op);
   2.261 -    op.u.close.port = tpmif->remote_evtchn;
   2.262 -    op.u.close.dom  = tpmif->domid;
   2.263 -    HYPERVISOR_event_channel_op(&op);
   2.264 +	op.u.close.port = tpmif->evtchn;
   2.265 +	op.u.close.dom = DOMID_SELF;
   2.266 +	HYPERVISOR_event_channel_op(&op);
   2.267 +	op.u.close.port = tpmif->remote_evtchn;
   2.268 +	op.u.close.dom = tpmif->domid;
   2.269 +	HYPERVISOR_event_channel_op(&op);
   2.270  
   2.271 -    if (tpmif->evtchn)
   2.272 -         unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   2.273 +	if (tpmif->evtchn)
   2.274 +		unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   2.275  
   2.276 -    if (tpmif->tx) {
   2.277 -        unmap_frontend_page(tpmif);
   2.278 -        vfree(tpmif->tx);
   2.279 -    }
   2.280 +	if (tpmif->tx) {
   2.281 +		unmap_frontend_page(tpmif);
   2.282 +		vfree(tpmif->tx);
   2.283 +	}
   2.284  
   2.285 -    free_tpmif(tpmif);
   2.286 +	free_tpmif(tpmif);
   2.287  }
   2.288  
   2.289 -
   2.290 -void tpmif_disconnect_complete(tpmif_t * tpmif)
   2.291 +void
   2.292 +tpmif_disconnect_complete(tpmif_t * tpmif)
   2.293  {
   2.294 -    INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   2.295 -    schedule_work(&tpmif->work);
   2.296 +	INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   2.297 +	schedule_work(&tpmif->work);
   2.298  }
   2.299  
   2.300 -
   2.301 -void __init tpmif_interface_init(void)
   2.302 +void __init
   2.303 +tpmif_interface_init(void)
   2.304  {
   2.305 -    tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof(tpmif_t),
   2.306 -                                     0, 0, NULL, NULL);
   2.307 +	tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
   2.308 +					 0, 0, NULL, NULL);
   2.309  }
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 10:11:02 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 10:13:11 2005 +0000
     3.3 @@ -257,18 +257,24 @@ static int setup_tpmring(struct xenbus_d
     3.4  
     3.5  	tpm_allocate_buffers(tp);
     3.6  
     3.7 -	info->ring_ref = gnttab_claim_grant_reference(&gref_head);
     3.8 -	ASSERT(info->ring_ref != -ENOSPC);
     3.9 -	gnttab_grant_foreign_access_ref(info->ring_ref,
    3.10 -					backend_id,
    3.11 -					(virt_to_machine(tp->tx) >> PAGE_SHIFT),
    3.12 -					0);
    3.13 +	err = gnttab_grant_foreign_access(backend_id,
    3.14 +					  (virt_to_machine(tp->tx) >> PAGE_SHIFT),
    3.15 +					  0);
    3.16 +
    3.17 +	if (err == -ENOSPC) {
    3.18 +		free_page((unsigned long)sring);
    3.19 +		tp->tx = NULL;
    3.20 +		xenbus_dev_error(dev, err, "allocating grant reference");
    3.21 +		return err;
    3.22 +	}
    3.23 +	info->ring_ref = err;
    3.24  
    3.25  	op.u.alloc_unbound.dom = backend_id;
    3.26  	err = HYPERVISOR_event_channel_op(&op);
    3.27  	if (err) {
    3.28 +		gnttab_end_foreign_access(info->ring_ref, 0);
    3.29  		free_page((unsigned long)sring);
    3.30 -		tp->tx = 0;
    3.31 +		tp->tx = NULL;
    3.32  		xenbus_dev_error(dev, err, "allocating event channel");
    3.33  		return err;
    3.34  	}
    3.35 @@ -282,6 +288,7 @@ static void destroy_tpmring(struct tpmfr
    3.36  	tpmif_set_connected_state(tp,0);
    3.37  
    3.38  	if ( tp->tx != NULL ) {
    3.39 +		gnttab_end_foreign_access(info->ring_ref, 0);
    3.40  		free_page((unsigned long)tp->tx);
    3.41  		tp->tx = NULL;
    3.42  	}
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 10:11:02 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 10:13:11 2005 +0000
     4.3 @@ -2,7 +2,8 @@
     4.4  #define TPM_FRONT_H
     4.5  
     4.6  
     4.7 -struct tpm_private {
     4.8 +struct tpm_private
     4.9 +{
    4.10  	tpmif_tx_interface_t *tx;
    4.11  	unsigned int evtchn;
    4.12  	int connected;
    4.13 @@ -29,7 +30,8 @@ struct tpmfront_info
    4.14  };
    4.15  
    4.16  
    4.17 -struct tx_buffer {
    4.18 +struct tx_buffer
    4.19 +{
    4.20  	unsigned int size;	// available space in data
    4.21  	unsigned int len;	// used space in data
    4.22  	unsigned char *data;    // pointer to a page
     5.1 --- a/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 10:11:02 2005 +0000
     5.2 +++ b/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 10:13:11 2005 +0000
     5.3 @@ -39,7 +39,7 @@ class TPMifController(DevController):
     5.4          """@see DevController.getDeviceDetails"""
     5.5          
     5.6          devid = int(sxp.child_value(config, 'instance', '0'))
     5.7 -        log.error("The domain has a TPM with instance %d." % devid)
     5.8 +        log.debug("The domain has a TPM with instance %d." % devid)
     5.9  
    5.10          back  = { 'instance' : "%i" % devid }
    5.11          front = { 'handle' : "%i" % devid }
     6.1 --- a/xen/include/public/io/tpmif.h	Wed Sep 21 10:11:02 2005 +0000
     6.2 +++ b/xen/include/public/io/tpmif.h	Wed Sep 21 10:13:11 2005 +0000
     6.3 @@ -20,8 +20,7 @@ typedef struct {
     6.4      unsigned long addr;   /* Machine address of packet.   */
     6.5      int      ref;         /* grant table access reference */
     6.6      u16      id;          /* Echoed in response message.  */
     6.7 -    u16      size:15;     /* Packet size in bytes.        */
     6.8 -    u16      mapped:1;
     6.9 +    u16      size;        /* Packet size in bytes.        */
    6.10  } tpmif_tx_request_t;
    6.11  
    6.12  /*
    6.13 @@ -30,13 +29,16 @@ typedef struct {
    6.14   */
    6.15  typedef u32 TPMIF_RING_IDX;
    6.16  
    6.17 -#define TPMIF_TX_RING_SIZE 16
    6.18 +#define TPMIF_TX_RING_SIZE 10
    6.19  
    6.20  /* This structure must fit in a memory page. */
    6.21 +
    6.22  typedef struct {
    6.23 -    union {
    6.24 -        tpmif_tx_request_t  req;
    6.25 -    } ring[TPMIF_TX_RING_SIZE];
    6.26 +    tpmif_tx_request_t req;
    6.27 +} tpmif_ring_t;
    6.28 +
    6.29 +typedef struct {
    6.30 +    tpmif_ring_t ring[TPMIF_TX_RING_SIZE];
    6.31  } tpmif_tx_interface_t;
    6.32  
    6.33  #endif