/* * Manages grant mappings from other domains. * * Diego Ongaro , July 2008 * * Files of type FTYPE_GNTMAP contain a gntmap, which is an array of * (host address, grant handle) pairs. Grant handles come from a hypervisor map * operation and are needed for the corresponding unmap. * * This is a rather naive implementation in terms of performance. If we start * using it frequently, there's definitely some low-hanging fruit here. * * * 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. */ #include #include #include #include #include #include "gntmap.h" #define DEFAULT_MAX_GRANTS 128 struct gntmap_entry { unsigned long host_addr; grant_handle_t handle; }; static inline int gntmap_entry_used(struct gntmap_entry *entry) { return entry->host_addr != 0; } static struct gntmap_entry* gntmap_find_free_entry(struct gntmap *map) { int i; for (i = 0; i < map->nentries; i++) { if (!gntmap_entry_used(&map->entries[i])) return &map->entries[i]; } #ifdef GNTMAP_DEBUG printk("gntmap_find_free_entry(map=%p): all %d entries full\n", map, map->nentries); #endif return NULL; } static struct gntmap_entry* gntmap_find_entry(struct gntmap *map, unsigned long addr) { int i; for (i = 0; i < map->nentries; i++) { if (map->entries[i].host_addr == addr) return &map->entries[i]; } return NULL; } int gntmap_set_max_grants(struct gntmap *map, int count) { #ifdef GNTMAP_DEBUG printk("gntmap_set_max_grants(map=%p, count=%d)\n", map, count); #endif if (map->nentries != 0) return -EBUSY; map->entries = xmalloc_array(struct gntmap_entry, count); if (map->entries == NULL) return -ENOMEM; memset(map->entries, 0, sizeof(struct gntmap_entry) * count); map->nentries = count; return 0; } static int _gntmap_map_grant_ref(struct gntmap_entry *entry, unsigned long host_addr, uint32_t domid, uint32_t ref, int writable) { struct gnttab_map_grant_ref op; int rc; op.ref = (grant_ref_t) ref; op.dom = (domid_t) domid; op.host_addr = (uint64_t) host_addr; op.flags = GNTMAP_host_map; if (!writable) op.flags |= GNTMAP_readonly; rc = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1); if (rc != 0 || op.status != GNTST_okay) { printk("GNTTABOP_map_grant_ref failed: " "returned %d, status %" PRId16 "\n", rc, op.status); return rc != 0 ? rc : op.status; } entry->host_addr = host_addr; entry->handle = op.handle; return 0; } static int _gntmap_unmap_grant_ref(struct gntmap_entry *entry) { struct gntta
PROTOCOL_DIR = protocol
CHIBIOS_DIR = $(PROTOCOL_DIR)/chibios


SRC += $(CHIBIOS_DIR)/usb_main.c
SRC += $(CHIBIOS_DIR)/main.c
SRC += usb_descriptor.c
SRC += $(CHIBIOS_DIR)/usb_driver.c

VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)
VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)/lufa_utils

OPT_DEFS += -DFIXED_CONTROL_ENDPOINT_SIZE=64
OPT_DEFS += -DFIXED_NUM_CONFIGURATIONS=1

ifeq ($(strip $(MIDI_ENABLE)), yes)
  include $(TMK_PATH)/protocol/midi.mk
endif