static void cmd_host_bus_list(struct vmm_chardev *cdev) { u32 num, dcount, count = vmm_devdrv_bus_count(); struct vmm_bus *b; vmm_cprintf(cdev, "----------------------------------------\n"); vmm_cprintf(cdev, " %-7s %-15s %-15s\n", "Num#", "Bus Name", "Device Count"); vmm_cprintf(cdev, "----------------------------------------\n"); for (num = 0; num < count; num++) { b = vmm_devdrv_bus(num); dcount = vmm_devdrv_bus_device_count(b); vmm_cprintf(cdev, " %-7d %-15s %-15d\n", num, b->name, dcount); } vmm_cprintf(cdev, "----------------------------------------\n"); }
static void cmd_host_class_list(struct vmm_chardev *cdev) { u32 num, dcount, count = vmm_devdrv_class_count(); struct vmm_class *c; vmm_cprintf(cdev, "----------------------------------------\n"); vmm_cprintf(cdev, " %-7s %-15s %-15s\n", "Num#", "Class Name", "Device Count"); vmm_cprintf(cdev, "----------------------------------------\n"); for (num = 0; num < count; num++) { c = vmm_devdrv_class(num); dcount = vmm_devdrv_class_device_count(c); vmm_cprintf(cdev, " %-7d %-15s %-15d\n", num, c->name, dcount); } vmm_cprintf(cdev, "----------------------------------------\n"); }
static void cmd_wboxtest_test_list(struct vmm_chardev *cdev) { struct cmd_wboxtest_test_list_args args; args.index = 0; args.cdev = cdev; vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); vmm_cprintf(cdev, " %-7s %-35s %-35s\n", "#", "Group Name", "Test Name"); vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); wboxtest_iterate(cmd_wboxtest_test_list_iter, &args); vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); }
static int cmd_flash_list(struct vmm_chardev *cdev, int __unused argc, char __unused **argv) { unsigned int i = 0; struct mtd_info *mtd = NULL; mtd = mtd_get_device(i++); if (!mtd) vmm_cprintf(cdev, "No MTD device registered\n"); while (mtd) { vmm_cprintf(cdev, "MTD %d: %s\n", i, mtd->name); mtd = mtd_get_device(i++); } return VMM_OK; }
static void cmd_host_vapool_bitmap(struct vmm_chardev *cdev, int colcnt) { u32 ite, total = vmm_host_vapool_total_page_count(); virtual_addr_t base = vmm_host_vapool_base(); vmm_cprintf(cdev, "0 : free\n"); vmm_cprintf(cdev, "1 : used"); for (ite = 0; ite < total; ite++) { if (umod32(ite, colcnt) == 0) { if (sizeof(u64) == sizeof(virtual_addr_t)) { vmm_cprintf(cdev, "\n0x%016llx: ", base + ite * VMM_PAGE_SIZE); } else { vmm_cprintf(cdev, "\n0x%08x: ", base + ite * VMM_PAGE_SIZE); } } if (vmm_host_vapool_page_isfree(base + ite * VMM_PAGE_SIZE)) { vmm_cprintf(cdev, "0"); } else { vmm_cprintf(cdev, "1"); } } vmm_cprintf(cdev, "\n"); }
int vmm_host_vapool_print_state(struct vmm_chardev *cdev) { unsigned long idx; vmm_cprintf(cdev, "VAPOOL State\n"); for (idx = VAPOOL_MIN_BIN; idx <= VAPOOL_MAX_BIN; idx++) { if (idx < 10) { vmm_cprintf(cdev, " [BLOCK %4dB]: ", 1<<idx); } else if (idx < 20) { vmm_cprintf(cdev, " [BLOCK %4dK]: ", 1<<(idx-10)); } else { vmm_cprintf(cdev, " [BLOCK %4dM]: ", 1<<(idx-20)); } vmm_cprintf(cdev, "%5d area(s), %5d free block(s)\n", buddy_bins_area_count(&vpctrl.ba, idx), buddy_bins_block_count(&vpctrl.ba, idx)); } vmm_cprintf(cdev, "VAPOOL House-Keeping State\n"); vmm_cprintf(cdev, " Buddy Areas: %d free out of %d\n", buddy_hk_area_free(&vpctrl.ba), buddy_hk_area_total(&vpctrl.ba)); return VMM_OK; }
static int heap_print_state(struct vmm_heap_control *heap, struct vmm_chardev *cdev, const char *name) { unsigned long idx; vmm_cprintf(cdev, "%s Heap State\n", name); for (idx = HEAP_MIN_BIN; idx <= HEAP_MAX_BIN; idx++) { if (idx < 10) { vmm_cprintf(cdev, " [BLOCK %4dB]: ", 1<<idx); } else if (idx < 20) { vmm_cprintf(cdev, " [BLOCK %4dK]: ", 1<<(idx-10)); } else { vmm_cprintf(cdev, " [BLOCK %4dM]: ", 1<<(idx-20)); } vmm_cprintf(cdev, "%5d area(s), %5d free block(s)\n", buddy_bins_area_count(&heap->ba, idx), buddy_bins_block_count(&heap->ba, idx)); } vmm_cprintf(cdev, "%s Heap House-Keeping State\n", name); vmm_cprintf(cdev, " Buddy Areas: %d free out of %d\n", buddy_hk_area_free(&heap->ba), buddy_hk_area_total(&heap->ba)); return VMM_OK; }
static int cmd_vfs_rm(struct vmm_chardev *cdev, const char *path) { int rc; struct stat st; rc = vfs_stat(path, &st); if (rc) { vmm_cprintf(cdev, "Path %s does not exist.\n", path); return rc; } if (!(st.st_mode & S_IFREG)) { vmm_cprintf(cdev, "Path %s should be regular file.\n", path); return VMM_EINVALID; } return vfs_unlink(path); }
static int cmd_vfs_rmdir(struct vmm_chardev *cdev, const char *path) { int rc; struct stat st; rc = vfs_stat(path, &st); if (rc) { vmm_cprintf(cdev, "Path %s does not exist.\n", path); return rc; } if (!(st.st_mode & S_IFDIR)) { vmm_cprintf(cdev, "Path %s should be directory.\n", path); return VMM_EINVALID; } return vfs_rmdir(path); }
static int cmd_vserial_recv_putchar(struct cmd_vserial_recvcntx *v, u8 ch) { switch (ch) { case '\r': vmm_cprintf(v->cdev, "\r[%s] ", v->name); break; case '\n': vmm_cprintf(v->cdev, "\n[%s] ", v->name); break; default: vmm_cputc(v->cdev, ch); break; }; return VMM_OK; }
static void cmd_flash_usage(struct vmm_chardev *cdev) { vmm_cprintf(cdev, "Usage:\n"); vmm_cprintf(cdev, " flash read <ID> [offset] [length] - Read flash " "device 'ID' \n" " from 'offset' (0 by default), up to 'length' bytes " "(a page size for NAND, a block size for NOR) by " "default)\n"); vmm_cprintf(cdev, " flash erase <ID> [offset] [length] - Erase " "flash device 'ID' \n" " from 'offset' (0 by default), up to 'length' bytes " "(the length should be block aligned)\n"); vmm_cprintf(cdev, " flash write <ID> <offset> <bytes> ... - Write " "on flash device 'ID' \n" " at 'offset' the given bytes given in hexadecimal format" "\n"); vmm_cprintf(cdev, " flash list - List flash device with their ID\n"); }
static int flash_question(struct vmm_chardev *cdev) { char ans = 0; vmm_cprintf(cdev, "Continue [Y/n]?\n"); ans = vmm_cgetc(cdev, FALSE); vmm_printf("\n"); return (ans == '\n') || (ans == 'y') || (ans == 'Y'); }
static void cmd_host_cpu_info(struct vmm_chardev *cdev) { u32 c, khz; char name[25]; vmm_cprintf(cdev, "%-25s: %s\n", "CPU Type", CONFIG_CPU); vmm_cprintf(cdev, "%-25s: %d\n", "CPU Present Count", vmm_num_present_cpus()); vmm_cprintf(cdev, "%-25s: %d\n", "CPU Possible Count", vmm_num_possible_cpus()); vmm_cprintf(cdev, "%-25s: %u\n", "CPU Online Count", vmm_num_online_cpus()); for_each_online_cpu(c) { khz = vmm_delay_estimate_cpu_khz(c); vmm_sprintf(name, "CPU%d Speed", c); vmm_cprintf(cdev, "%-25s: %d.%d MHz (Estimated)\n", name, udiv32(khz, 1000), umod32(khz, 1000)); } arch_cpu_print_info(cdev); }
static int cmd_flash_write(struct vmm_chardev *cdev, int argc, char **argv) { int err = VMM_OK; int idx = 0; size_t retlen = 0; flash_op op; u_char *buf = NULL; if (VMM_OK != (err = flash_args_common(cdev, argc, argv, &op))) { return err; } vmm_cprintf(cdev, "Before writing, the %s block at 0x%08X must have " "been erased?\n", op.mtd->name, op.offset & ~op.mtd->erasesize_mask); if (!flash_question(cdev)) { vmm_cprintf(cdev, "Exiting...\n"); return VMM_OK; } if (argc - 4 <= 0) { vmm_cprintf(cdev, "Nothing to write, exiting\n"); return VMM_OK; } if (NULL == (buf = vmm_malloc(argc - 5))) { return VMM_ENOMEM; } for (idx = 0; idx < argc - 4; ++idx) { buf[idx] = strtoull(argv[idx + 4], NULL, 16); vmm_cprintf(cdev, "Writing at 0x%08X 0x%02X\n", op.offset + idx, buf[idx]); } if (0 != mtd_write(op.mtd, op.offset, argc - 4, &retlen, buf)) { vmm_cprintf(cdev, "Failed to write %s at 0x%08X\n", op.mtd->name, op.offset); } vmm_free(buf); return err; }
static int flash_erase(struct vmm_chardev *cdev, flash_op *op) { struct erase_info info; if (op->len & op->mtd->erasesize_mask) { vmm_cprintf(cdev, "Uncorrect length 0x%X, a block size is " "0x%08X\n", op->len, op->mtd->erasesize); return VMM_EFAIL; } op->offset &= ~op->mtd->erasesize_mask; while (op->len) { if (mtd_block_isbad(op->mtd, op->offset)) { vmm_cprintf(cdev, "%s block at 0x%08X is bad, " "skipping...", op->mtd->name, op->offset); op->offset += op->mtd->erasesize; op->len -= op->mtd->erasesize; continue; } vmm_cprintf(cdev, "This will erasing the %s block at " "0x%08X\n", op->mtd->name, op->offset); if (!flash_question(cdev)) { vmm_cprintf(cdev, "Skipping...\n"); op->offset += op->mtd->erasesize; op->len -= op->mtd->erasesize; continue; } vmm_cprintf(cdev, "Erasing...\n"); memset(&info, 0, sizeof (struct erase_info)); info.mtd = op->mtd; info.addr = op->offset; info.len = op->len; info.priv = (u_long)cdev; info.callback = flash_erase_cb; vmm_printf("Sizeof %zu, Addr 0x%p, cb 0x%p\n", sizeof (struct erase_info), &info, info.callback); mtd_erase(op->mtd, &info); } return VMM_OK; }
static void cmd_host_cpu_stats(struct vmm_chardev *cdev) { u32 c, p, khz, util; vmm_cprintf(cdev, "----------------------------------------" "-------------------------\n"); vmm_cprintf(cdev, " %4s %15s %13s %12s %16s\n", "CPU#", "Speed (MHz)", "Util. (%)", "IRQs (%)", "Active VCPUs"); vmm_cprintf(cdev, "----------------------------------------" "-------------------------\n"); for_each_online_cpu(c) { vmm_cprintf(cdev, " %4d", c); khz = vmm_delay_estimate_cpu_khz(c); vmm_cprintf(cdev, " %11d.%03d", udiv32(khz, 1000), umod32(khz, 1000)); util = udiv64(vmm_scheduler_idle_time(c) * 1000, vmm_scheduler_get_sample_period(c)); util = (util > 1000) ? 1000 : util; util = 1000 - util; vmm_cprintf(cdev, " %11d.%01d", udiv32(util, 10), umod32(util, 10)); util = udiv64(vmm_scheduler_irq_time(c) * 1000, vmm_scheduler_get_sample_period(c)); util = (util > 1000) ? 1000 : util; vmm_cprintf(cdev, " %10d.%01d", udiv32(util, 10), umod32(util, 10)); util = 1; for (p = VMM_VCPU_MIN_PRIORITY; p <= VMM_VCPU_MAX_PRIORITY; p++) { util += vmm_scheduler_ready_count(c, p); } vmm_cprintf(cdev, " %15d ", util); vmm_cprintf(cdev, "\n"); } vmm_cprintf(cdev, "----------------------------------------" "-------------------------\n"); }
void vmm_host_irqext_debug_dump(struct vmm_chardev *cdev) { int idx = 0; irq_flags_t flags; vmm_read_lock_irqsave_lite(&iectrl.lock, flags); vmm_cprintf(cdev, "%d extended IRQs\n", iectrl.count); vmm_cprintf(cdev, " BITMAP:\n"); for (idx = 0; idx < BITS_TO_LONGS(iectrl.count); ++idx) { if (0 == (idx % 4)) { vmm_cprintf(cdev, "\n %d:", idx); } vmm_cprintf(cdev, " 0x%x", iectrl.bitmap[idx]); } vmm_cprintf(cdev, "\n"); vmm_read_unlock_irqrestore_lite(&iectrl.lock, flags); }
static int cmd_host_bus_list_iter(struct vmm_bus *b, void *data) { u32 dcount; struct cmd_host_list_iter *p = data; dcount = vmm_devdrv_bus_device_count(b); vmm_cprintf(p->cdev, " %-7d %-15s %-15d\n", p->num++, b->name, dcount); return VMM_OK; }
int cmd_rtcdev_sync_device(struct vmm_chardev *cdev, const char * name) { int rc; struct vmm_rtcdev * rtc = vmm_rtcdev_find(name); if (!rtc) { vmm_cprintf(cdev, "Error: cannot find rtc %s\n", name); return VMM_EFAIL; } rc = vmm_rtcdev_sync_device(rtc); if (rc) { vmm_cprintf(cdev, "Error: sync_device failed for rtc %s\n", name); return rc; } return VMM_OK; }
static int cmd_blockdev_list_iter(struct vmm_blockdev *bdev, void *data) { struct vmm_chardev *cdev = data; vmm_cprintf(cdev, " %-16s %-16s %-16ll %-11d %-16ll\n", bdev->name, (bdev->parent) ? bdev->parent->name : "---", bdev->start_lba, bdev->block_size, bdev->num_blocks); return VMM_OK; }
static int cmd_vfs_sha256(struct vmm_chardev *cdev, const char *path) { int fd, rc, i; u32 len; size_t buf_rd; u8 buf[VFS_LOAD_BUF_SZ]; struct stat st; struct sha256_context sha256c; sha256_digest_t digest; fd = vfs_open(path, O_RDONLY, 0); if (fd < 0) { vmm_cprintf(cdev, "Failed to open %s\n", path); return fd; } rc = vfs_fstat(fd, &st); if (rc) { vfs_close(fd); vmm_cprintf(cdev, "Failed to stat %s\n", path); return rc; } if (!(st.st_mode & S_IFREG)) { vfs_close(fd); vmm_cprintf(cdev, "Cannot read %s\n", path); return VMM_EINVALID; } len = st.st_size; sha256_init(&sha256c); while (len) { memset(buf, 0, sizeof(buf)); buf_rd = (len < VFS_LOAD_BUF_SZ) ? len : VFS_LOAD_BUF_SZ; buf_rd = vfs_read(fd, buf, buf_rd); if (buf_rd < 1) { break; } sha256_update(&sha256c, buf, buf_rd); } sha256_final(digest, &sha256c); vmm_cprintf(cdev, "SHA-256 Digest: "); for (i = 0; i < SHA256_DIGEST_LEN; i++) vmm_cprintf(cdev, "%x", digest[i]); vmm_cprintf(cdev, "\n"); rc = vfs_close(fd); if (rc) { vmm_cprintf(cdev, "Failed to close %s\n", path); return rc; } return VMM_OK; }
void cmd_memory_usage(struct vmm_chardev *cdev) { vmm_cprintf(cdev, "Usage: "); vmm_cprintf(cdev, " memory help\n"); vmm_cprintf(cdev, " memory dump8 <phys_addr> <count>\n"); vmm_cprintf(cdev, " memory dump16 <phys_addr> <count>\n"); vmm_cprintf(cdev, " memory dump32 <phys_addr> <count>\n"); vmm_cprintf(cdev, " memory modify8 <phys_addr> " "<val0> <val1> ...\n"); vmm_cprintf(cdev, " memory modify16 <phys_addr> " "<val0> <val1> ...\n"); vmm_cprintf(cdev, " memory modify32 <phys_addr> " "<val0> <val1> ...\n"); vmm_cprintf(cdev, " memory copy <phys_addr> <src_phys_addr> " "<byte_count>\n"); }
static void cmd_vsdaemon_usage(struct vmm_chardev *cdev) { vmm_cprintf(cdev, "Usage:\n"); vmm_cprintf(cdev, " vsdaemon help\n"); vmm_cprintf(cdev, " vsdaemon transport_list\n"); vmm_cprintf(cdev, " vsdaemon list\n"); vmm_cprintf(cdev, " vsdaemon create <transport_name>" " <vserial_name> <daemon_name> ...\n"); vmm_cprintf(cdev, " vsdaemon create mterm" " <vserial_name> <daemon_name>\n"); vmm_cprintf(cdev, " vsdaemon create chardev" " <vserial_name> <daemon_name> <chardev_name>\n"); vmm_cprintf(cdev, " vsdaemon create telnet" " <vserial_name> <daemon_name> <port_number>\n"); vmm_cprintf(cdev, " vsdaemon destroy <daemon_name>\n"); }
static void cmd_thread_list(struct vmm_chardev *cdev) { int rc, index, count; char state[10], name[VMM_FIELD_NAME_SIZE]; struct vmm_thread *tinfo; vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); vmm_cprintf(cdev, " %-6s %-7s %-10s %-53s\n", "ID ", "Prio", "State", "Name"); vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); count = vmm_threads_count(); for (index = 0; index < count; index++) { tinfo = vmm_threads_index2thread(index); switch (vmm_threads_get_state(tinfo)) { case VMM_THREAD_STATE_CREATED: strcpy(state, "Created"); break; case VMM_THREAD_STATE_RUNNING: strcpy(state, "Running"); break; case VMM_THREAD_STATE_SLEEPING: strcpy(state, "Sleeping"); break; case VMM_THREAD_STATE_STOPPED: strcpy(state, "Stopped"); break; default: strcpy(state, "Invalid"); break; } if ((rc = vmm_threads_get_name(name, tinfo))) { strcpy(name, "(NA)"); } vmm_cprintf(cdev, " %-6d %-7d %-10s %-53s\n", vmm_threads_get_id(tinfo), vmm_threads_get_priority(tinfo), state, name); } vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); }
static int cmd_rtcdev_sync_wallclock(struct vmm_chardev *cdev, const char * name) { int rc; struct rtc_device *rtc = rtc_device_find(name); if (!rtc) { vmm_cprintf(cdev, "Error: cannot find rtc %s\n", name); return VMM_EFAIL; } rc = rtc_device_sync_wallclock(rtc); if (rc) { vmm_cprintf(cdev, "Error: sync_wallclock failed " "for rtc %s\n", name); return rc; } return VMM_OK; }
static int cmd_vfs_fslist(struct vmm_chardev *cdev) { int num, count; struct filesystem *fs; vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); vmm_cprintf(cdev, " %-9s %-69s\n", "Num", "Name"); vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); count = vfs_filesystem_count(); for (num = 0; num < count; num++) { fs = vfs_filesystem_get(num); vmm_cprintf(cdev, " %-9d %-69s\n", num, fs->name); } vmm_cprintf(cdev, "----------------------------------------" "----------------------------------------\n"); return VMM_OK; }
static int i2c_print_dev(struct device *dev, void *data) { struct vmm_chardev *cdev = data; struct i2c_adapter *adap = NULL; if (NULL != (adap = i2c_verify_adapter(dev))) { vmm_cprintf(cdev, " %2d %-16s %-16s", adap->nr, dev->name, "adapter"); } else { vmm_cprintf(cdev, " %-16s %-16s", dev->name, "client"); } if (dev->parent) { vmm_cprintf(cdev, " %-16s\n", dev->parent->name); } else { vmm_cprintf(cdev, " ----------------\n"); } return 0; }
static int cmd_vfs_mv(struct vmm_chardev *cdev, const char *old_path, const char *new_path) { int rc; struct stat st; rc = vfs_stat(old_path, &st); if (rc) { vmm_cprintf(cdev, "Path %s does not exist.\n", old_path); return rc; } rc = vfs_rename(old_path, new_path); if (rc) { vmm_cprintf(cdev, "Failed to rename.\n"); return rc; } return VMM_OK; }
static int cmd_vsdaemon_destroy(struct vmm_chardev *cdev, const char *name) { int ret = VMM_EFAIL; if ((ret = vsdaemon_destroy(name))) { vmm_cprintf(cdev, "Failed to destroy vsdaemon %s\n", name); } return ret; }
static void cmd_vsdaemon_transport_list(struct vmm_chardev *cdev) { int i, count; struct vsdaemon_transport *trans; vmm_cprintf(cdev, "------------------------------\n"); vmm_cprintf(cdev, " %-4s %-24s\n", "#", "Transport Name"); vmm_cprintf(cdev, "------------------------------\n"); count = vsdaemon_transport_count(); for (i = 0; i < count; i++) { trans = vsdaemon_transport_get(i); if (!trans) { continue; } vmm_cprintf(cdev, " %-4d %-24s\n", i, trans->name); } vmm_cprintf(cdev, "------------------------------\n"); }