static void rec_packet(libvchan_t * con) { char done = 1; int data[4]; struct camera_data ca; libvchan_wait(con); int readSize = libvchan_recv(con, data, 4*sizeof(int)); assert(readSize == 4*sizeof(int)); DVM("received bounding box packet\n"); //here are your corners Lee! ca.bbox_l = data[0]; ca.bbox_r = data[1]; ca.bbox_t = data[2]; ca.bbox_b = data[3]; /* int xmid = ((r + l) / 2) - 160; */ /* int ymid = ((b + t) / 2) - 100; */ /* ymid = -1.0*ymid; //sign change (based on how the camera is oriented) */ /* //here are your angles Lee! */ /* ca.angle_x = ((float) xmid)*(0.00410666); */ /* ca.angle_y = ((float) ymid)*(0.00410666); */ if (camera_vm_Output_from_vm_0_write_camera_data(&ca)) { DVM("wrote bounding box\n"); } else { DVM("failed to write bouding box\n"); } DVM("camera_vm: sending ack\n"); libvchan_send(con, &done, sizeof(char)); }
static int handle_page_fault(vm_t* vm, fault_t* fault) { struct device* d; /* See if the device is already in our address space */ d = vm_find_device_by_ipa(vm, fault_get_address(fault)); if (d != NULL) { if (d->devid == DEV_RAM) { DRAMFAULT("[%s] %s fault @ 0x%x from 0x%x\n", d->name, (fault_is_read(fault)) ? "read" : "write", fault_get_address(fault), fault_get_ctx(fault)->pc); } else { DDEVFAULT("[%s] %s fault @ 0x%x from 0x%x\n", d->name, (fault_is_read(fault)) ? "read" : "write", fault_get_address(fault), fault_get_ctx(fault)->pc); } return d->handle_page_fault(d, vm, fault); } else { #ifdef CONFIG_ONDEMAND_DEVICE_INSTALL uintptr_t addr = fault_get_address(fault) & ~0xfff; void* mapped; switch (addr) { case 0: printf("VM fault on IPA 0x%08x\n", 0); print_fault(fault); return -1; default: mapped = map_vm_device(vm, addr, addr, seL4_AllRights); if (mapped) { DVM("WARNING: Blindly mapped device @ 0x%x for PC 0x%x\n", fault_get_address(fault), fault_get_ctx(fault)->pc); restart_fault(fault); return 0; } mapped = map_vm_ram(vm, addr); if (mapped) { DVM("WARNING: Mapped RAM for device @ 0x%x for PC 0%x\n", fault_get_address(fault), fault_get_ctx(fault)->pc); restart_fault(fault); return 0; } DVM("Unhandled fault on address 0x%x\n", (uint32_t)addr); } #endif print_fault(fault); abandon_fault(fault); return -1; } }
int run(void) { libvchan_t *connection; DVM("vm_camera wrapper init\n"); con.data_buf = (void *)share_mem; connection = libvchan_server_init(0, 25, 0, 0); if(connection != NULL) connection = link_vchan_comp(connection, &con); assert(connection != NULL); DVM("vm_camera connection active\n"); while(1) { DVM("camera_vm.packet\n"); rec_packet(connection); } }
int vm_copyout_atags(vm_t* vm, struct atag_list* atags, uint32_t addr) { vspace_t *vm_vspace, *vmm_vspace; void* vm_addr, *vmm_addr, *buf; reservation_t res; vka_t* vka; vka_object_t frame; size_t size; struct atag_list* atag_cur; int err; vka = vm->vka; vm_addr = (void*)(addr & ~0xfff); vm_vspace = vm_get_vspace(vm); vmm_vspace = vm->vmm_vspace; /* Make sure we don't cross a page boundary * NOTE: the next page will usually be used by linux for PT! */ for (size = 0, atag_cur = atags; atag_cur != NULL; atag_cur = atag_cur->next) { size += atags_size_bytes(atag_cur); } size += 8; /* NULL tag */ assert((addr & 0xfff) + size < 0x1000); /* Create a frame (and a copy for the VMM) */ err = vka_alloc_frame(vka, 12, &frame); assert(!err); if (err) { return -1; } /* Map the frame to the VMM */ vmm_addr = vspace_map_pages(vmm_vspace, &frame.cptr, NULL, seL4_AllRights, 1, 12, 0); assert(vmm_addr); /* Copy in the atags */ buf = vmm_addr + (addr & 0xfff); for (atag_cur = atags; atag_cur != NULL; atag_cur = atag_cur->next) { int tag_size = atags_size_bytes(atag_cur); DVM("ATAG copy 0x%x<-0x%x %d\n", (uint32_t)buf, (uint32_t)atag_cur->hdr, tag_size); memcpy(buf, atag_cur->hdr, tag_size); buf += tag_size; } /* NULL tag terminator */ memset(buf, 0, 8); /* Unmap the page and map it into the VM */ vspace_unmap_pages(vmm_vspace, vmm_addr, 1, 12, NULL); res = vspace_reserve_range_at(vm_vspace, vm_addr, 0x1000, seL4_AllRights, 0); assert(res.res); if (!res.res) { vka_free_object(vka, &frame); return -1; } err = vspace_map_pages_at_vaddr(vm_vspace, &frame.cptr, NULL, vm_addr, 1, 12, res); vspace_free_reservation(vm_vspace, res); assert(!err); if (err) { printf("Failed to provide memory\n"); vka_free_object(vka, &frame); return -1; } return 0; }