iPXE
Defines | Functions
xengrant.h File Reference

Xen grant tables. More...

#include <stdint.h>
#include <stdlib.h>
#include <ipxe/io.h>
#include <ipxe/xen.h>
#include <xen/grant_table.h>

Go to the source code of this file.

Defines

#define XENGRANT_FAIL_RATE   0
 Induced failure rate (for testing)

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static __attribute__ ((always_inline)) int xengrant_query_size(struct xen_hypervisor *xen
 Query grant table size.
int xengrant_alloc (struct xen_hypervisor *xen, grant_ref_t *refs, unsigned int count)
 Allocate grant references.
void xengrant_free (struct xen_hypervisor *xen, grant_ref_t *refs, unsigned int count)
 Free grant references.

Detailed Description

Xen grant tables.

Definition in file xengrant.h.


Define Documentation

#define XENGRANT_FAIL_RATE   0

Induced failure rate (for testing)

Definition at line 19 of file xengrant.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

Query grant table size.

Parameters:
xenXen hypervisor
sizeTable size
Return values:
xenrcXen status code
int xengrant_alloc ( struct xen_hypervisor xen,
grant_ref_t refs,
unsigned int  count 
) [read]

Allocate grant references.

Parameters:
xenXen hypervisor
refsGrant references to fill in
countNumber of references
Return values:
rcReturn status code

Definition at line 148 of file xengrant.c.

References assert, count, DBGC, DBGC2, DOMID_SELF, ENOBUFS, GNTTAB_NR_RESERVED_ENTRIES, xen_hypervisor::grant, GTF_type_mask, hdr, readw(), xen_grant::ref, ref, xen_grant::used, and writew().

Referenced by netfront_probe().

                                          {
        struct grant_entry_header *hdr;
        unsigned int entries = xengrant_entries ( xen );
        unsigned int mask = ( entries - 1 );
        unsigned int check = 0;
        unsigned int avail;
        unsigned int ref;

        /* Fail unless we have enough references available */
        avail = ( entries - xen->grant.used - GNTTAB_NR_RESERVED_ENTRIES );
        if ( avail < count ) {
                DBGC ( xen, "XENGRANT cannot allocate %d references (only %d "
                       "of %d available)\n", count, avail, entries );
                return -ENOBUFS;
        }
        DBGC ( xen, "XENGRANT allocating %d references (from %d of %d "
               "available)\n", count, avail, entries );

        /* Update number of references used */
        xen->grant.used += count;

        /* Find unused references */
        for ( ref = xen->grant.ref ; count ; ref = ( ( ref + 1 ) & mask ) ) {

                /* Sanity check */
                assert ( check++ < entries );

                /* Skip reserved references */
                if ( ref < GNTTAB_NR_RESERVED_ENTRIES )
                        continue;

                /* Skip in-use references */
                hdr = xengrant_header ( xen, ref );
                if ( readw ( &hdr->flags ) & GTF_type_mask )
                        continue;
                if ( readw ( &hdr->domid ) == DOMID_SELF )
                        continue;

                /* Zero reference */
                xengrant_zero ( xen, hdr );

                /* Mark reference as in-use.  We leave the flags as
                 * empty (to avoid creating a valid grant table entry)
                 * and set the domid to DOMID_SELF.
                 */
                writew ( DOMID_SELF, &hdr->domid );
                DBGC2 ( xen, "XENGRANT allocated ref %d\n", ref );

                /* Record reference */
                refs[--count] = ref;
        }

        /* Update cursor */
        xen->grant.ref = ref;

        return 0;
}
void xengrant_free ( struct xen_hypervisor xen,
grant_ref_t refs,
unsigned int  count 
)

Free grant references.

Parameters:
xenXen hypervisor
refsGrant references
countNumber of references

Definition at line 214 of file xengrant.c.

References assert, count, DBGC2, hdr, and ref.

Referenced by netfront_probe(), and netfront_remove().

                                          {
        struct grant_entry_header *hdr;
        unsigned int ref;
        unsigned int i;

        /* Free references */
        for ( i = 0 ; i < count ; i++ ) {

                /* Sanity check */
                ref = refs[i];
                assert ( ref < xengrant_entries ( xen ) );

                /* Zero reference */
                hdr = xengrant_header ( xen, ref );
                xengrant_zero ( xen, hdr );
                DBGC2 ( xen, "XENGRANT freed ref %d\n", ref );
        }
}