iPXE
Macros | Functions | Variables
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.

Macros

#define XENGRANT_FAIL_RATE   0
 Induced failure rate (for testing) More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __attribute__ ((always_inline)) int xengrant_query_size(struct xen_hypervisor *xen
 Query grant table size. More...
 
 return (container_of(&v1->flags, struct grant_entry_header, flags))
 
static void xengrant_zero (struct xen_hypervisor *xen, struct grant_entry_header *hdr)
 Zero grant table entry. More...
 
 assert ((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
 
 writew (0, &hdr->flags)
 
 writew (DOMID_SELF, &hdr->domid)
 
 if ((XENGRANT_FAIL_RATE > 0) &&(random() % XENGRANT_FAIL_RATE)==0)
 
 if (sizeof(physaddr_t)==sizeof(uint64_t))
 
 wmb ()
 
 writew ((GTF_permit_access|subflags), &hdr->flags)
 
int xengrant_init (struct xen_hypervisor *xen)
 Initialise grant table. More...
 
int xengrant_alloc (struct xen_hypervisor *xen, grant_ref_t *refs, unsigned int count)
 Allocate grant references. More...
 
void xengrant_free (struct xen_hypervisor *xen, grant_ref_t *refs, unsigned int count)
 Free grant references. More...
 

Variables

static struct gnttab_query_sizesize
 
static struct gnttab_set_version * version
 
static grant_ref_t ref
 
 v1 = &xen->grant.table[ ref << xen->grant.shift ]
 
static grant_ref_t domid_t domid
 
static grant_ref_t domid_t unsigned int subflags
 
static grant_ref_t domid_t unsigned int void * page
 
union grant_entry_v2 * v2 = xengrant_v2 ( hdr )
 
unsigned long frame = ( virt_to_phys ( page ) / PAGE_SIZE )
 
 else
 
 return
 

Detailed Description

Xen grant tables.

Definition in file xengrant.h.

Macro Definition Documentation

◆ XENGRANT_FAIL_RATE

#define XENGRANT_FAIL_RATE   0

Induced failure rate (for testing)

Definition at line 19 of file xengrant.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Query grant table size.

Permit access to a page.

Invalidate access to a page.

Get version 2 grant table entry.

Get version 1 grant table entry.

Get grant table entry header.

Get number of grant table entries.

Get grant table version.

Set grant table version.

Parameters
xenXen hypervisor
sizeTable size
Return values
xenrcXen status code
Parameters
xenXen hypervisor
versionVersion
Return values
xenrcXen status code
Parameters
xenXen hypervisor
Return values
entriesNumber of grant table entries
Parameters
xenXen hypervisor
refGrant reference
Return values
hdrGrant table entry header
Parameters
hdrGrant table entry header
Return values
v1Version 1 grant table entry
Parameters
hdrGrant table entry header
Return values
v2Version 2 grant table entry
Parameters
xenXen hypervisor
refGrant reference
xenXen hypervisor
refGrant reference
domidDomain ID
subflagsAdditional flags
pagePage start
Return values
rcReturn status code

Definition at line 75 of file xengrant.h.

76  {
77 
78  return ( ( xen->grant.len / sizeof ( xen->grant.table[0] ) )
79  >> xen->grant.shift );
80 }

References xen_hypervisor::grant, xen_grant::len, xen_grant::shift, xen_grant::table, and xen_device::xen.

◆ return()

return ( container_of &->,,  flags)

◆ xengrant_zero()

static void xengrant_zero ( struct xen_hypervisor xen,
struct grant_entry_header *  hdr 
)
inlinestatic

Zero grant table entry.

Parameters
xenXen hypervisor
hdrGrant table entry header

Definition at line 127 of file xengrant.h.

128  {
129  uint32_t *dword = ( ( uint32_t * ) hdr );
130  unsigned int i = ( ( sizeof ( xen->grant.table[0] ) / sizeof ( *dword ))
131  << xen->grant.shift );
132 
133  while ( i-- )
134  writel ( 0, dword++ );
135 }
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
struct grant_entry_v1 * table
Grant table entries.
Definition: xen.h:31
unsigned int uint32_t
Definition: stdint.h:12
uint32_t hdr
Message header.
Definition: intelvf.h:12
unsigned int shift
Entry size shift (for later version tables)
Definition: xen.h:35
struct xen_grant grant
Grant table.
Definition: xen.h:57
unsigned long int dword
Definition: smc9000.h:40

References xen_hypervisor::grant, hdr, xen_grant::shift, xen_grant::table, and writel().

Referenced by xengrant_alloc(), and xengrant_free().

◆ assert()

assert ( (readw(&hdr->flags) &(GTF_reading|GTF_writing))  = =0)

Referenced by __attribute__(), _print_label(), a3c90x_internal_ReadEeprom(), acm_transmit(), aes_decrypt(), aes_encrypt(), alloc_iob_raw(), alloc_memblock(), ansicol_set(), ansicol_set_pair(), aoecmd_ata_cmd(), aoecmd_cfg_cmd(), aoecmd_free(), aoecmd_tx(), arbel_alloc_icm(), arbel_close(), arbel_cmd(), arbel_complete(), arbel_map_vpm(), arbel_post_send(), arbel_start_firmware(), asn1_okx(), atadev_read_capacity(), ath5k_handle_rx(), axge_in_complete(), bigint_mod_multiply_raw(), bios_ansi_seq(), bios_handle_ed(), blktrans_xferbuf_read(), blktrans_xferbuf_write(), block_translate(), bzimage_exec(), cachedhcp_init(), cbc_decrypt(), cbc_encrypt(), cbc_xor(), chap_init(), chap_respond(), chap_update(), check_blocks(), cipher_cost(), cms_test_exec(), cms_verify_signer_info(), com32_exec_loop(), comboot_exec_loop(), concat_args(), deflate_accumulate(), deflate_bin(), deflate_consume(), deflate_inflate(), deflate_init(), der_probe(), dhcp_create_request(), dhcpv6_rx(), dhcpv6_tx(), dns_xfer_deliver(), drbg_generate(), drbg_instantiate(), drbg_reseed(), drbg_uninstantiate(), ecb_decrypt(), ecb_encrypt(), ecm_probe(), edit_setting(), eepro_transmit(), efab_fill_rx_queue(), efab_receive(), efab_transmit(), efab_transmit_done(), efi_bofm_start(), efi_bofm_stop(), efi_driver_stop(), efi_file_install(), efi_handle_ed(), efi_image_exec(), efi_local_open_path(), efi_local_step(), efi_pxe_udp_deliver(), efi_snp_add_claim(), efi_snp_set_mode(), efi_urealloc(), efi_usb_close(), efi_usb_probe(), efi_usb_remove(), efi_usb_sync_transfer(), efifb_glyphs(), efx_hunt_alloc_special_buffer(), efx_hunt_receive(), efx_hunt_rxq_fill(), efx_hunt_transmit(), efx_hunt_transmit_done(), ehci_bus_close(), ehci_bus_open(), ehci_bus_poll(), ehci_dequeue(), ehci_device_address(), ehci_endpoint_capabilities(), ehci_endpoint_message(), ehci_endpoint_reset(), ehci_enqueue(), ehci_remove(), ehci_ring_fill(), ehci_ring_free(), ena_refill_rx(), eoib_transmit(), exanic_expired(), exanic_i2c_read_bit(), exanic_i2c_write_bit(), exanic_probe_port(), expand_tokens(), falcon_alloc_special_buffer(), falcon_mdio_read(), falcon_mdio_write(), falcon_spi_rw(), fbcon_handle_ed(), fbcon_init(), fbcon_scroll(), fc_els_free(), fc_els_step(), fc_peer_close(), fc_peer_decrement(), fc_peer_examine(), fc_peer_login(), fc_ulp_attach(), fc_ulp_close(), fc_ulp_login(), fc_xchg_free(), fcoe_expired(), fcpcmd_recv_rddata(), fcpcmd_send_cmnd(), fcpcmd_send_wrdata(), fcpdev_identify_device(), fcpdev_scsi_command(), fdt_traverse(), fetch_setting_alloc(), fetchf_setting(), fetchf_setting_copy(), fetchn_setting(), find_smbios_entry(), find_smbios_structure(), flexboot_nodnic_complete(), flexboot_nodnic_post_send(), format_busdevfn_setting(), free_iob(), free_memblock(), free_tls(), free_tls_session(), free_usb(), free_usb_bus(), free_usb_hub(), gdbserial_recv(), gdbudp_ensure_netdev_open(), generic_settings_clear(), golan_complete(), golan_provide_pages(), guestinfo_fetch_type(), guestrpc_command(), hash_df(), hermon_close(), hermon_cmd(), hermon_complete(), hermon_map_icm(), hermon_map_vpm(), hermon_mod_stat_cfg(), hermon_post_send(), hermon_set_port_type(), hermon_start_firmware(), hide_umalloc(), history_append(), history_cleanup(), history_free(), hmac_drbg_generate(), hmac_drbg_instantiate(), hmac_drbg_reseed(), hmac_drbg_update(), hmac_drbg_update_key(), hmac_drbg_update_value(), http_block_read(), http_conn_close(), http_connect(), http_format_basic_auth(), http_format_digest_auth(), http_format_ntlm_auth(), http_init_transfer_chunked(), http_open_post_uri(), http_parse_headers(), http_rx_chunk_data(), http_transfer_complete(), http_tx_request(), hub_remove(), hunt_mcdi_copyin(), hv_post_message(), hv_wait_for_message(), hvm_ioremap(), ib_destroy_cq(), ib_destroy_qp(), ib_mcast_attach(), ib_mcast_detach(), ib_mcast_join(), ib_mcast_leave(), ib_mi_send(), ib_open(), ib_pull(), ibft_fill_target_chap(), ibft_fill_target_reverse_chap(), ibft_install(), icm_align(), icplus_read_eeprom(), icplus_refill_rx(), image_asn1(), image_exec(), image_replace(), init_i2c_bit_basher(), init_spi_bit_basher(), initrd_swap(), insert_delete(), int13_device_path_info(), int13_guess_geometry(), int22(), intel_read_eeprom(), intel_refill_rx(), intelvf_mbox_msg(), intelxl_admin_command(), intelxl_refill_rx(), iob_pad(), iob_pull(), iob_split(), ioremap_pages(), iounmap_pages(), ipv6_add_miniroute(), iscsi_build_login_request_strings(), iscsi_fetch_settings(), iscsi_open_connection(), iscsi_rx_buffered_data(), iscsi_rx_data_in(), iscsi_scsi_done(), iscsi_socket_deliver(), iscsi_start_command(), iscsi_start_login(), iscsi_start_tx(), iscsi_tx_data_out(), iscsi_tx_step(), jump_scroll(), jump_scroll_key(), jump_scroll_move(), last_opened_ibdev(), last_opened_netdev(), linda_complete_recv(), linda_complete_send(), linda_ib_epb_mod_reg(), linda_ib_epb_ram_xfer(), linda_post_recv(), linda_post_send(), line_buffer(), longjmp_okx(), main_loop(), md4_digest(), md4_final(), md5_digest(), md5_final(), memcpy_test_speed(), menu_loop(), myson_refill_rx(), natsemi_refill_rx(), nbi_process_segments(), ncm_probe(), ndp_register_settings(), neighbour_free(), net80211_change_channel(), net80211_mgmt_dequeue(), net80211_prepare_assoc(), net80211_prepare_probe(), net80211_probe_start(), net80211_set_rate_idx(), netdev_fetch_bustype(), netdev_tx_flush(), netfront_create_ring(), netfront_open(), netfront_pull(), netfront_push(), netvsc_create_ring(), netvsc_destroy_ring(), netvsc_transmit(), nii_get_init_info(), nii_poll_tx(), numerate_int_setting(), nvs_read(), nvs_write(), ocsp_check(), ocsp_validate(), parse_fc_port(), parse_fc_port_id(), parse_gdb_transport(), parse_integer(), parse_netdev(), parse_netdev_configurator(), parse_setting(), parse_settings(), parse_string(), pci_msix_map(), pci_vpd_resize(), peerblk_decrypt(), peerblk_dequeue(), peerblk_enqueue(), peerblk_expired(), peerblk_parse_block(), peerblk_parse_header(), peerblk_reset(), peerdisc_destroy(), peerdisc_open(), peerdist_discovery_reply_values(), peerdist_info(), peerdist_info_block(), peerdist_info_hash_ntoa(), peerdist_info_passphrase_okx(), peerdist_info_segment(), peerdist_info_segment_hash(), peerdist_info_v1(), peerdist_info_v1_block(), peerdist_info_v1_block_offset(), peerdist_info_v1_segment(), peerdist_info_v2(), peerdist_info_v2_block(), peerdist_info_v2_segment(), peermux_block_deliver(), pem_asn1(), pem_marker(), phantom_clp_cmd(), phantom_crb_access_128m(), phantom_crb_access_2m(), phantom_crb_access_32m(), phantom_dmesg(), phantom_fetch_setting(), phantom_poll(), phantom_probe(), phantom_refill_rx_ring(), phantom_store_setting(), phantom_transmit(), ping_rx(), pit8254_speaker_delay(), pixbuf_okx(), png_interlace(), png_pixels(), png_pixels_pass(), png_unfilter(), png_unfilter_pass(), pnm_type(), pool_add(), pool_expired(), profile_update(), pxe_fake_cached_info(), pxe_menu_boot(), pxe_netdev_close(), pxe_netdev_open(), pxe_udp_deliver(), pxenv_udp_read(), pxenv_undi_get_information(), qib7322_ahb_mod_reg(), qib7322_complete_recv(), qib7322_complete_send(), qib7322_post_recv(), qib7322_post_send(), qib7322_probe(), read_smbios_string(), read_smbios_structure(), read_user(), readline_history(), realloc(), realtek_refill_rx(), register_settings(), register_usb(), register_usb_bus(), reparse_options(), rfc_tcpip_chksum(), rndis_tx_defer(), rsa_encode_digest(), rtc_unhook_isr(), run_tests(), sandev_command(), sandev_command_read_capacity(), sandev_command_rw(), sandev_free(), sandev_reopen(), save_setting(), sdi_exec(), sha1_digest(), sha1_final(), sha256_digest(), sha256_final(), sha512_digest(), sha512_final(), show_menu(), shuffle(), skge_up(), skge_xmit_frame(), sky2_status_intr(), sky2_tx_complete(), slam_parse_multicast_address(), slam_pull_header(), slam_put_value(), smbios_version(), spi_bit_rw(), srp_open(), srpcmd_free(), storef_setting(), storen_setting(), tcp_close(), tcp_expired(), tcp_rx_opts(), tcp_rx_seq(), tcp_wait_expired(), tcp_xmit_sack(), tcpip_random_okx(), test_ok(), tg3_rx_complete(), threewire_read(), threewire_write(), timer_expired(), tls_cipherstream_deliver(), tls_generate_keys(), tls_newdata_process_data(), tls_newdata_process_header(), tls_restart(), tls_set_cipher(), tls_split_stream(), tls_tx_step(), tls_validator_done(), txnic_complete_sqe(), txnic_lmac_probe(), txnic_lmac_probe_all(), txnic_lmac_remove(), txnic_lmac_remove_all(), txnic_refill_rq(), uhci_bus_close(), uhci_bus_open(), uhci_dequeue(), uhci_device_address(), uhci_endpoint_message(), uhci_endpoint_poll(), uhci_endpoint_stream(), uhci_enqueue(), uhci_remove(), uhci_restart(), uhci_ring_fill(), uhci_ring_free(), undinet_call(), undinet_hook_isr(), undinet_unhook_isr(), unregister_sandev(), unregister_usb(), unregister_usb_bus(), usb_attached(), usb_complete_err(), usb_control(), usb_deconfigure(), usb_describe(), usb_endpoint_close(), usb_endpoint_reset(), usb_flush(), usb_free_address(), usb_hotplug(), usb_message(), usb_prefill(), usb_probe_all(), usb_refill(), usb_remove_all(), usbio_close(), usbio_endpoint_message(), usbio_interfaces(), usbio_interrupt_callback(), usbio_interrupt_poll(), usbio_open(), usbkbd_consume(), usbkbd_fill(), validator_start_ocsp(), validator_xfer_close(), vmbus_open(), vmbus_poll(), vmbus_probe(), vmbus_remove_channels(), vmbus_send(), vmbus_send_cancellation(), vmbus_send_completion(), vmbus_send_control(), vmbus_send_data(), vmbus_xfer_page_iobufs(), vmxnet3_refill_rx(), vmxnet3_transmit(), vpm_ioread16(), vpm_ioread32(), vpm_ioread8(), vpm_iowrite16(), vpm_iowrite32(), vpm_iowrite8(), vxge_hw_device_terminate(), write_cmd(), x509_check_signature(), x509_test_exec(), xcm_free(), xengrant_alloc(), xengrant_free(), xenstore_request(), xhci_abort(), xhci_address_device_input(), xhci_bus_close(), xhci_command_free(), xhci_complete(), xhci_dcbaa_free(), xhci_dequeue(), xhci_device_open(), xhci_endpoint_message(), xhci_endpoint_open(), xhci_enqueue(), xhci_enqueue_multi(), xhci_init(), xhci_port_status(), xhci_ring_alloc(), xhci_ring_free(), xhci_ring_remaining(), xhci_scratchpad_alloc(), xhci_scratchpad_free(), xhci_transfer(), and xsigo_free().

◆ writew() [1/3]

writew ( ,
&hdr->  flags 
)

◆ writew() [2/3]

writew ( DOMID_SELF  ,
&hdr->  domid 
)

◆ if() [1/2]

if ( (XENGRANT_FAIL_RATE > 0) &&(random() % XENGRANT_FAIL_RATE = = 0)

Definition at line 181 of file xengrant.h.

182  {
183  return -EAGAIN;
184  }
#define EAGAIN
Resource temporarily unavailable.
Definition: errno.h:318

References EAGAIN.

◆ if() [2/2]

if ( sizeof(physaddr_t = = sizeof ( uint64_t ))

Definition at line 192 of file xengrant.h.

192  {
193 
194  /* 64-bit system */
195  if ( xen->grant.shift ) {
196  /* Version 2 table: no possible failure */
197  writeq ( frame, &v2->full_page.frame );
198  } else {
199  /* Version 1 table: may fail if address above 16TB */
200  if ( frame > 0xffffffffUL )
201  return -ERANGE;
202  writel ( frame, &v1->frame );
203  }
204 
205  } else {
v1
Definition: xengrant.h:93
unsigned long frame
Definition: xengrant.h:178
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
#define ERANGE
Result too large.
Definition: errno.h:639
union grant_entry_v2 * v2
Definition: xengrant.h:177
void writeq(uint64_t data, volatile uint64_t *io_addr)
Write 64-bit qword to memory-mapped device.

References ERANGE, frame, xen_hypervisor::grant, xen_grant::shift, v1, v2, writel(), and writeq().

◆ wmb()

wmb ( )

Referenced by __vxge_hw_kdfc_swapper_set(), __vxge_hw_legacy_swapper_set(), __vxge_hw_non_offload_db_post(), __vxge_hw_pio_mem_write64(), __vxge_hw_read_rts_ds(), __vxge_hw_vpath_kdfc_configure(), __vxge_hw_vpath_pci_read(), __vxge_hw_vpath_swapper_set(), amd8111e_init_rx_ring(), amd8111e_poll(), amd8111e_transmit(), atl1e_read_phy_reg(), atl1e_reset_hw(), atl1e_tx_queue(), atl1e_write_phy_reg(), b44_transmit(), bnx2_poll(), bnx2_transmit(), clear_b0_fpga_memories(), ehci_async_schedule(), ehci_endpoint_reset(), ehci_enqueue(), ehci_periodic_schedule(), ena_admin(), ena_destroy_admin(), ena_refill_rx(), ena_transmit(), exanic_close(), exanic_open(), exanic_transmit(), falcon_read(), falcon_write(), falcon_write_sram(), flexboot_nodnic_arm_cq(), forcedeth_transmit(), golan_cmd_init(), golan_eq_update_ci(), golan_post_recv(), golan_post_send(), hunt_mcdi_copyin(), icplus_refill_rx(), icplus_transmit(), intel_refill_rx(), intel_transmit(), intelxl_admin_command(), intelxl_refill_admin(), intelxl_refill_rx(), intelxl_transmit(), is_command_finished(), jme_disable_rx_engine(), jme_disable_tx_engine(), jme_enable_rx_engine(), jme_enable_tx_engine(), jme_fill_tx_desc(), jme_mdio_write(), jme_set_clean_rxdesc(), jme_setup_wakeup_frame(), myri10ge_command(), myri10ge_interrupt_handler(), myri10ge_net_poll(), myri10ge_net_transmit(), myri10ge_post_receive(), myson_refill_rx(), myson_transmit(), natsemi_refill_rx(), natsemi_transmit(), nv_alloc_rx(), pci_push(), pcnet32_refill_rx_ring(), pcnet32_setup_init_block(), pcnet32_transmit(), phantom_poll(), phantom_post_cds(), phantom_post_rds(), realtek_refill_rx(), realtek_transmit(), rhine_refill_rx(), rhine_transmit(), send_command(), shomron_tx_uar_send_db(), sis190_give_to_asic(), sis190_make_unusable_by_asic(), sis190_transmit(), skge_poll(), skge_rx_reuse(), skge_rx_setup(), skge_up(), skge_xmit_frame(), sky2_put_idx(), sky2_rx_stop(), txnic_refill_rq(), txnic_send(), uhci_async_schedule(), uhci_describe(), uhci_endpoint_poll(), uhci_enqueue(), uhci_periodic_schedule(), uhci_restart(), velocity_refill_rx(), velocity_transmit(), vmbus_send(), vmxnet3_refill_rx(), vmxnet3_transmit(), vring_add_buf(), vring_detach(), vring_get_buf(), vring_kick(), vring_more_used(), vxge_hw_device_hw_info_get(), vxge_hw_set_fw_api(), vxge_hw_vpath_doorbell_rx(), vxge_open(), xenstore_recv(), xenstore_send(), xhci_doorbell(), and xhci_enqueue().

◆ writew() [3/3]

writew ( (GTF_permit_access|subflags ,
&hdr->  flags 
)

◆ xengrant_init()

int xengrant_init ( struct xen_hypervisor xen)

Initialise grant table.

Parameters
xenXen hypervisor
Return values
rcReturn status code

Definition at line 70 of file xengrant.c.

70  {
71  struct gnttab_query_size size;
72  struct gnttab_set_version set_version;
73  struct gnttab_get_version get_version;
74  struct grant_entry_v1 *v1;
75  union grant_entry_v2 *v2;
76  unsigned int version;
77  int xenrc;
78  int rc;
79 
80  /* Get grant table size */
81  size.dom = DOMID_SELF;
82  if ( ( xenrc = xengrant_query_size ( xen, &size ) ) != 0 ) {
83  rc = -EXEN ( xenrc );
84  DBGC ( xen, "XENGRANT could not get table size: %s\n",
85  strerror ( rc ) );
86  return rc;
87  }
88  xen->grant.len = ( size.nr_frames * PAGE_SIZE );
89 
90  /* Set grant table version, if applicable */
91  set_version.version = XENGRANT_TRY_VERSION;
92  if ( ( xenrc = xengrant_set_version ( xen, &set_version ) ) != 0 ) {
93  rc = -EXEN ( xenrc );
94  DBGC ( xen, "XENGRANT could not set version %d: %s\n",
96  /* Continue; use whatever version is current */
97  }
98 
99  /* Get grant table version */
100  get_version.dom = DOMID_SELF;
101  get_version.pad = 0;
102  if ( ( xenrc = xengrant_get_version ( xen, &get_version ) ) == 0 ) {
103  version = get_version.version;
104  switch ( version ) {
105 
106  case 0:
107  /* Version not yet specified: will be version 1 */
108  version = 1;
109  break;
110 
111  case 1 :
112  /* Version 1 table: nothing special to do */
113  break;
114 
115  case 2:
116  /* Version 2 table: configure shift appropriately */
117  xen->grant.shift = ( fls ( sizeof ( *v2 ) /
118  sizeof ( *v1 ) ) - 1 );
119  break;
120 
121  default:
122  /* Unsupported version */
123  DBGC ( xen, "XENGRANT detected unsupported version "
124  "%d\n", version );
125  return -ENOTSUP;
126 
127  }
128  } else {
129  rc = -EXEN ( xenrc );
130  DBGC ( xen, "XENGRANT could not get version (assuming v1): "
131  "%s\n", strerror ( rc ) );
132  version = 1;
133  }
134 
135  DBGC ( xen, "XENGRANT using v%d table with %d entries\n",
136  version, xengrant_entries ( xen ) );
137  return 0;
138 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
v1
Definition: xengrant.h:93
#define PAGE_SIZE
Page size.
Definition: io.h:27
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define EXEN(xenrc)
Convert a Xen status code to an iPXE status code.
Definition: xen.h:87
u32 version
Version number.
Definition: ath9k_hw.c:1983
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
Definition: grant_table.h:133
union grant_entry_v2 * v2
Definition: xengrant.h:177
#define XENGRANT_TRY_VERSION
Grant table version to try setting.
Definition: xengrant.c:62
unsigned int shift
Entry size shift (for later version tables)
Definition: xen.h:35
struct xen_grant grant
Grant table.
Definition: xen.h:57
#define DOMID_SELF
Definition: xen.h:501
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
size_t len
Total grant table length.
Definition: xen.h:33
#define fls(x)
Find last (i.e.
Definition: strings.h:166

References DBGC, DOMID_SELF, ENOTSUP, EXEN, fls, xen_hypervisor::grant, xen_grant::len, PAGE_SIZE, rc, xen_grant::shift, size, strerror(), v1, v2, version, and XENGRANT_TRY_VERSION.

Referenced by hvm_map_grant().

◆ xengrant_alloc()

int xengrant_alloc ( struct xen_hypervisor xen,
grant_ref_t refs,
unsigned int  count 
)

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.

149  {
150  struct grant_entry_header *hdr;
151  unsigned int entries = xengrant_entries ( xen );
152  unsigned int mask = ( entries - 1 );
153  unsigned int check = 0;
154  unsigned int avail;
155  unsigned int ref;
156 
157  /* Fail unless we have enough references available */
158  avail = ( entries - xen->grant.used - GNTTAB_NR_RESERVED_ENTRIES );
159  if ( avail < count ) {
160  DBGC ( xen, "XENGRANT cannot allocate %d references (only %d "
161  "of %d available)\n", count, avail, entries );
162  return -ENOBUFS;
163  }
164  DBGC ( xen, "XENGRANT allocating %d references (from %d of %d "
165  "available)\n", count, avail, entries );
166 
167  /* Update number of references used */
168  xen->grant.used += count;
169 
170  /* Find unused references */
171  for ( ref = xen->grant.ref ; count ; ref = ( ( ref + 1 ) & mask ) ) {
172 
173  /* Sanity check */
174  assert ( check++ < entries );
175 
176  /* Skip reserved references */
178  continue;
179 
180  /* Skip in-use references */
181  hdr = xengrant_header ( xen, ref );
182  if ( readw ( &hdr->flags ) & GTF_type_mask )
183  continue;
184  if ( readw ( &hdr->domid ) == DOMID_SELF )
185  continue;
186 
187  /* Zero reference */
188  xengrant_zero ( xen, hdr );
189 
190  /* Mark reference as in-use. We leave the flags as
191  * empty (to avoid creating a valid grant table entry)
192  * and set the domid to DOMID_SELF.
193  */
194  writew ( DOMID_SELF, &hdr->domid );
195  DBGC2 ( xen, "XENGRANT allocated ref %d\n", ref );
196 
197  /* Record reference */
198  refs[--count] = ref;
199  }
200 
201  /* Update cursor */
202  xen->grant.ref = ref;
203 
204  return 0;
205 }
uint16_t readw(volatile uint16_t *io_addr)
Read 16-bit word from memory-mapped device.
#define DBGC(...)
Definition: compiler.h:505
#define GNTTAB_NR_RESERVED_ENTRIES
Definition: grant_table.h:149
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define GTF_type_mask
Definition: grant_table.h:166
static const char grant_ref_t unsigned int struct io_buffer grant_ref_t * refs
Definition: netfront.h:93
unsigned int ref
Most recently used grant reference.
Definition: xen.h:39
uint32_t hdr
Message header.
Definition: intelvf.h:12
#define ENOBUFS
No buffer space available.
Definition: errno.h:498
#define DBGC2(...)
Definition: compiler.h:522
struct xen_grant grant
Grant table.
Definition: xen.h:57
#define writew
Definition: w89c840.c:159
uint16_t count
Number of entries.
Definition: ena.h:22
#define DOMID_SELF
Definition: xen.h:501
static const char grant_ref_t ref
Definition: netfront.h:91
static void xengrant_zero(struct xen_hypervisor *xen, struct grant_entry_header *hdr)
Zero grant table entry.
Definition: xengrant.h:127
unsigned int used
Number of grant table entries in use.
Definition: xen.h:37

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

Referenced by netfront_probe().

◆ xengrant_free()

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.

215  {
216  struct grant_entry_header *hdr;
217  unsigned int ref;
218  unsigned int i;
219 
220  /* Free references */
221  for ( i = 0 ; i < count ; i++ ) {
222 
223  /* Sanity check */
224  ref = refs[i];
225  assert ( ref < xengrant_entries ( xen ) );
226 
227  /* Zero reference */
228  hdr = xengrant_header ( xen, ref );
229  xengrant_zero ( xen, hdr );
230  DBGC2 ( xen, "XENGRANT freed ref %d\n", ref );
231  }
232 }
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static const char grant_ref_t unsigned int struct io_buffer grant_ref_t * refs
Definition: netfront.h:93
uint32_t hdr
Message header.
Definition: intelvf.h:12
#define DBGC2(...)
Definition: compiler.h:522
uint16_t count
Number of entries.
Definition: ena.h:22
static const char grant_ref_t ref
Definition: netfront.h:91
static void xengrant_zero(struct xen_hypervisor *xen, struct grant_entry_header *hdr)
Zero grant table entry.
Definition: xengrant.h:127

References assert(), count, DBGC2, hdr, ref, refs, and xengrant_zero().

Referenced by netfront_probe(), and netfront_remove().

Variable Documentation

◆ size

struct gnttab_query_size* size
Initial value:
{
return xen_hypercall_3 ( xen, __HYPERVISOR_grant_table_op,
virt_to_phys ( size ), 1 )
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
#define __HYPERVISOR_grant_table_op
Definition: xen.h:86
#define GNTTABOP_query_size
Definition: grant_table.h:307
static struct gnttab_query_size * size
Definition: xengrant.h:30

Definition at line 30 of file xengrant.h.

◆ version

struct gnttab_get_version* version
Initial value:
{
return xen_hypercall_3 ( xen, __HYPERVISOR_grant_table_op,
GNTTABOP_set_version,
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
static struct gnttab_set_version * version
Definition: xengrant.h:46
#define __HYPERVISOR_grant_table_op
Definition: xen.h:86

Definition at line 46 of file xengrant.h.

◆ ref

Initial value:

Definition at line 90 of file xengrant.h.

◆ v1

struct grant_entry_v1 * v1 = &xen->grant.table[ ref << xen->grant.shift ]

Definition at line 93 of file xengrant.h.

Referenced by if(), and xengrant_init().

◆ domid

Definition at line 173 of file xengrant.h.

◆ subflags

grant_ref_t domid_t unsigned int subflags

Definition at line 173 of file xengrant.h.

◆ page

grant_ref_t domid_t unsigned int void* page
Initial value:
{
struct grant_entry_header *hdr = xengrant_header ( xen, ref )
uint32_t hdr
Message header.
Definition: intelvf.h:12
static grant_ref_t ref
Definition: xengrant.h:90

Definition at line 174 of file xengrant.h.

Referenced by hv_alloc_pages(), and hv_free_pages().

◆ v2

union grant_entry_v2* v2 = xengrant_v2 ( hdr )

Definition at line 177 of file xengrant.h.

Referenced by if(), and xengrant_init().

◆ frame

unsigned long frame = ( virt_to_phys ( page ) / PAGE_SIZE )

◆ else

else
Initial value:
{
if ( xen->grant.shift ) {
writel ( frame, &v2->full_page.frame );
} else {
writel ( frame, &v1->frame );
}
}
writew ( domid, &hdr->domid )
v1
Definition: xengrant.h:93
unsigned long frame
Definition: xengrant.h:178
void writel(uint32_t data, volatile uint32_t *io_addr)
Write 32-bit dword to memory-mapped device.
static grant_ref_t domid_t domid
Definition: xengrant.h:173
uint32_t hdr
Message header.
Definition: intelvf.h:12
union grant_entry_v2 * v2
Definition: xengrant.h:177
writew(0, &hdr->flags)

Definition at line 205 of file xengrant.h.

◆ return

return

Definition at line 223 of file xengrant.h.