dspctl.c

来自「Omap5910 上实现双核通信 DSP GateWay」· C语言 代码 · 共 1,167 行 · 第 1/2 页

C
1,167
字号
static int do_gbl_idle(char **argv){	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("setting DSP global idle\n");	ioctl(fd, OMAP_DSP_IOCTL_GBL_IDLE);	close(fd);	return 0;}static int do_cpu_idle(char **argv){	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("setting DSP CPU idle\n");	ioctl(fd, OMAP_DSP_IOCTL_CPU_IDLE);	close(fd);	return 0;}static int do_suspend(char **argv){	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("suspending DSP\n");	ioctl(fd, OMAP_DSP_IOCTL_SUSPEND);	close(fd);	return 0;}static int do_resume(char **argv){	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("resuming DSP\n");	ioctl(fd, OMAP_DSP_IOCTL_RESUME);	close(fd);	return 0;}static int do_dspcfg(char **argv){	int fd;	int ret;	int n_task;	if ((ret = dsptask_dir_check()) != 0)		return ret;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("DSP configuration ...");	if (ioctl(fd, OMAP_DSP_IOCTL_DSPCFG) < 0) {		printf("failed\n");		perror("");		return 1;	}	printf("succeeded\n");	if ((n_task = ioctl(fd, OMAP_DSP_IOCTL_TASKCNT)) < 0) {		perror("TASKCNT");		return 1;	}	close(fd);	return dev_mklink(n_task);}static int do_dspuncfg(char **argv){	int fd;	int n_task;	int ret = 0;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	if ((n_task = ioctl(fd, OMAP_DSP_IOCTL_TASKCNT)) < 0) {		perror("TASKCNT");		return 1;	}	ret = dev_unlink(n_task);	printf("releasing resources for DSP\n");	ioctl(fd, OMAP_DSP_IOCTL_DSPUNCFG);	close(fd);	return ret;}static int do_poll(char **argv){	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("polling DSP ... ");	if (ioctl(fd, OMAP_DSP_IOCTL_POLL) < 0) {		printf("failed\n");		return 1;	}	printf("succeeded\n");	close(fd);	return 0;}static int do_kmem_reserve(char **argv){	unsigned long size;	int ret;	int fd;	size = strtoul(argv[2], NULL, 16);	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("reserving kernel memory for DSP: size = 0x%lx\n", size);	ret = ioctl(fd, OMAP_DSP_MEM_IOCTL_KMEM_RESERVE, &size);	close(fd);	if (ret < 0) {		perror("KMEM_RESERVE");		return 1;	}	if (ret < size) {		printf("!!! only %d (0x%x) bytes could be reserved.\n", ret, ret);	}	printf("%d (0x%x) bytes reserved.\n", ret, ret);	return 0;}static int do_kmem_release(char **argv){	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("releasing kernel memory for DSP\n");	ioctl(fd, OMAP_DSP_MEM_IOCTL_KMEM_RELEASE);	close(fd);	return 0;}static int do_exmap(char **argv){	struct omap_dsp_mapinfo mapinfo;	int ret;	int fd;	mapinfo.dspadr = strtoul(argv[2], NULL, 16);	mapinfo.size   = strtoul(argv[3], NULL, 16);	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("mapping external memory for DSP: "	       "dspadr = 0x%06lx, size = 0x%lx\n",	       mapinfo.dspadr, mapinfo.size);	ret = ioctl(fd, OMAP_DSP_MEM_IOCTL_EXMAP, &mapinfo);	close(fd);	if (ret < 0) {		perror("EXMAP");		return 1;	}	if (ret < mapinfo.size) {		printf("!!! only %d (0x%x) bytes could be mapped.\n", ret, ret);	}	printf("%d (0x%x) bytes mapped.\n", ret, ret);	return 0;}static int do_exunmap(char **argv){	unsigned long dspadr = strtoul(argv[2], NULL, 16);	int ret;	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("releasing external memory map for DSP: "	       "dspadr = 0x%06lx\n", dspadr);	ret = ioctl(fd, OMAP_DSP_MEM_IOCTL_EXUNMAP, dspadr);	close(fd);	if (ret < 0) {		perror("EXUNMAP");		return 1;	}	printf("%d (0x%x) bytes unmapped.\n", ret, ret);	return 0;}static int do_mapflush(char **argv){	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("flush DSP TLB.\n");	ioctl(fd, OMAP_DSP_MEM_IOCTL_EXMAP_FLUSH);	close(fd);	return 0;}static int do_fbexport(char **argv){	unsigned long dspadr = strtoul(argv[2], NULL, 16);	int ret;	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("mapping frame buffer to DSP space:\n"	       "  dspadr hint   = 0x%06lx\n", dspadr);	ret = ioctl(fd, OMAP_DSP_MEM_IOCTL_FBEXPORT, &dspadr);	close(fd);	if (ret < 0) {		perror("FBEXPORT");		return 1;	}	printf("  dspadr actual = 0x%06lx\n", dspadr);	printf("%d (0x%x) bytes mapped.\n", ret, ret);	return 0;}static int do_mmuinit(char **argv){	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("initialize DSP MMU.\n");	ioctl(fd, OMAP_DSP_MEM_IOCTL_MMUINIT);	close(fd);	return 0;}static int do_mmuitack(char **argv){	int fd;	if ((fd = open(DSPMEMDEVNM, O_RDWR)) < 0) {		perror("open dspmem device");		return 1;	}	printf("sending DSP MMU interrupt acknowledge.\n");	ioctl(fd, OMAP_DSP_MEM_IOCTL_MMUITACK);	close(fd);	return 0;}static int do_mkdev(char **argv){	int ret;	int fd;	if ((fd = open(TWCHDEVNM, O_RDWR)) < 0) {		perror("open task watch device");		return 1;	}	printf("create DSP task device.\n");	ret = ioctl(fd, OMAP_DSP_TWCH_IOCTL_MKDEV, argv[2]);	close(fd);	if (ret < 0) {		perror("MKDEV");		return 1;	}	return 0;}static int do_rmdev(char **argv){	int ret;	int fd;	if ((fd = open(TWCHDEVNM, O_RDWR)) < 0) {		perror("open task watch device");		return 1;	}	printf("remove DSP task device.\n");	ret = ioctl(fd, OMAP_DSP_TWCH_IOCTL_RMDEV, argv[2]);	close(fd);	if (ret < 0) {		perror("RMDEV");		return 1;	}	return 0;}static int do_tadd(char **argv){	struct omap_dsp_taddinfo taddinfo;	int ret;	int fd;	taddinfo.minor   = strtoul(argv[2], NULL, 10);	taddinfo.taskadr = strtoul(argv[3], NULL, 16);	if ((fd = open(TWCHDEVNM, O_RDWR)) < 0) {		perror("open task watch device");		return 1;	}	printf("add DSP task.\n");	ret = ioctl(fd, OMAP_DSP_TWCH_IOCTL_TADD, &taddinfo);	close(fd);	if (ret < 0) {		perror("TADD");		return 1;	}	return 0;}static int do_tdel(char **argv){	unsigned char minor = strtoul(argv[2], NULL, 10);	int ret;	int fd;	if ((fd = open(TWCHDEVNM, O_RDWR)) < 0) {		perror("open task watch device");		return 1;	}	printf("delete DSP task.\n");	ret = ioctl(fd, OMAP_DSP_TWCH_IOCTL_TDEL, minor);	close(fd);	if (ret < 0) {		perror("TDEL");		return 1;	}	return 0;}static int do_getvar(char **argv){	char buf[32]; /* maximum size for omap_dsp_varinfo */	struct omap_dsp_varinfo *var = (void *)buf;	int valc;	int ret;	int fd;	int i;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	var->varid = strtoul(argv[2], NULL, 16);	printf("DSP variable read: varid=0x%02x\n", var->varid);	switch (var->varid) {	case OMAP_DSP_MBCMD_VARID_ICRMASK:		valc = 1;		break;	case OMAP_DSP_MBCMD_VARID_LOADINFO:		valc = 5;		break;	default:		fprintf(stderr, "illegal varid\n");		return 1;	}	ret = ioctl(fd, OMAP_DSP_IOCTL_GETVAR, var);	close(fd);	if (ret < 0) {		printf("\n");		perror("GETVAR");		return 1;	}	for (i = 0; i < valc; i++) {		printf("  val[%d]=0x%04x\n", i, var->val[i]);	}	return 0;}static int do_setvar_1(char **argv){	char buf[32]; /* maximum size for omap_dsp_varinfo */	struct omap_dsp_varinfo *var = (void *)buf;	int valc = 1;	int ret;	int fd;	int i;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	var->varid = strtoul(argv[2], NULL, 16);	printf("DSP variable write: varid=0x%02x", var->varid);	switch (var->varid) {	case OMAP_DSP_MBCMD_VARID_ICRMASK:		/* valc = 1; */		break;	default:		fprintf(stderr, "illegal varid\n");		return 1;	}	for (i = 0; i < valc; i++) {		var->val[i] = strtoul(argv[3+i], NULL, 16);		printf("    val[%d]=0x%04x\n", i, var->val[i]);	}	ret = ioctl(fd, OMAP_DSP_IOCTL_SETVAR, var);	close(fd);	if (ret < 0) {		perror("SETVAR");		return 1;	}	return 0;}static int do_regread(char **argv){	return __regread(SPACE_MEM, strtoul(argv[2], NULL, 16));}static int do_regread_io(char **argv){	if (strcmp(argv[2], "-io")) {		usage(argv[0]);		return 1;	}	return __regread(SPACE_IO, strtoul(argv[3], NULL, 16));}static int __regread(enum regspace space, unsigned short adr){	struct omap_dsp_reginfo reg;	unsigned int ctlcmd;	int ret;	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("DSP register read: adr=%s:0x%04x",	       (space == SPACE_MEM) ? "MEM" : "IO",  adr);	ctlcmd = (space == SPACE_MEM) ? OMAP_DSP_IOCTL_REGMEMR :					OMAP_DSP_IOCTL_REGIOR;	reg.adr = adr;	ret = ioctl(fd, ctlcmd, &reg);	close(fd);	if (ret < 0) {		printf("\n");		perror("REGREAD");		return 1;	}	printf(", val=0x%04x\n", reg.val);	return 0;}static int do_regwrite_io(char **argv){	if (strcmp(argv[2], "-io")) {		usage(argv[0]);		return 1;	}	return __regwrite(SPACE_IO,			  strtoul(argv[3], NULL, 16),			  strtoul(argv[4], NULL, 16));}static int do_regwrite(char **argv){	return __regwrite(SPACE_MEM,			  strtoul(argv[2], NULL, 16),			  strtoul(argv[3], NULL, 16));}static int __regwrite(enum regspace space, unsigned short adr,		      unsigned short val){	struct omap_dsp_reginfo reg;	unsigned int ctlcmd;	int ret;	int fd;	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("DSP register write: adr=%s:0x%04x, val=0x%04x\n",	       (space == SPACE_MEM) ? "MEM" : "IO",  adr, val);	ctlcmd = (space == SPACE_MEM) ? OMAP_DSP_IOCTL_REGMEMW :					OMAP_DSP_IOCTL_REGIOW;	reg.adr = adr;	reg.val = val;	ret = ioctl(fd, ctlcmd, &reg);	close(fd);	if (ret < 0) {		perror("REGWRITE");		return 1;	}	return 0;}static int do_runlevel(char **argv){	char *level_name = argv[2];	unsigned char level;	int fd;	if (!strcmp(level_name, "user")) {		level = OMAP_DSP_MBCMD_RUNLEVEL_USER;	} else if (!strcmp(level_name, "super")) {		level = OMAP_DSP_MBCMD_RUNLEVEL_SUPER;	} else {		printf("unknown runlevel %s\n", level_name);		return 1;	}	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("setting DSP runlevel to %s\n", level_name);	ioctl(fd, OMAP_DSP_IOCTL_RUNLEVEL, level);	close(fd);	return 0;}static int do_mbsend(char **argv){	struct omap_dsp_mailbox_cmd mbcmd;	int fd;	mbcmd.cmd  = strtoul(argv[2], NULL, 16);	mbcmd.data = strtoul(argv[3], NULL, 16);	if ((fd = open(CTLDEVNM, O_RDWR)) < 0) {		perror("open control device");		return 1;	}	printf("sending mailbox command to DSP: cmd = 0x%02x, data = 0x%02x\n",	       mbcmd.cmd, mbcmd.data);	ioctl(fd, OMAP_DSP_IOCTL_MBSEND, &mbcmd);	close(fd);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?