예제 #1
0
int CMEM_init(void)
{
    int flags;
    unsigned int version;

    __D("init: entered - ref_count %d, cmem_fd %d\n", ref_count, cmem_fd);

    if (cmem_fd >= 0) {
        ref_count++;
        __D("init: /dev/cmem already opened, incremented ref_count %d\n",
            ref_count);
        return 0;
    }

    cmem_fd = open("/dev/cmem", O_RDWR);

    if (cmem_fd == -1) {
        __E("init: Failed to open /dev/cmem: '%s'\n", strerror(errno));
        return -1;
    }

    ref_count++;

    __D("init: successfully opened /dev/cmem, matching driver version...\n");

    version = CMEM_getVersion();
    if ((version & 0xffff0000) != (CMEM_VERSION & 0xffff0000)) {
        __E("init: major version mismatch between interface and driver.\n");
        __E("    needs driver version %#x, got %#x\n", CMEM_VERSION, version);
        CMEM_exit();
        return -1;
    }
    else if ((version & 0x0000ffff) < (CMEM_VERSION & 0x0000ffff)) {
        __E("init: minor version mismatch between interface and driver.\n");
        __E("    needs driver minor version %#x or greater.\n"
            "    got minor version %#x (full version %#x)\n",
            CMEM_VERSION & 0x0000ffff, version & 0x0000ffff, version);
        CMEM_exit();
        return -1;
    }

    __D("init: ... match good (%#x)\n", version);

    flags = fcntl(cmem_fd, F_GETFD);
    if (flags != -1) {
        fcntl(cmem_fd, F_SETFD, flags | FD_CLOEXEC);
    }
    else {
        __E("init: fcntl(F_GETFD) failed: '%s'\n", strerror(errno));
    }

    __D("init: exiting, returning success\n");

    return 0;
}
예제 #2
0
파일: apitest.c 프로젝트: black1tulip/DVSDK
int main(int argc, char *argv[])
{
    int size;
    int version;
    CMEM_BlockAttrs attrs;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of bytes to allocate>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    size = atoi(argv[1]);

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
        fprintf(stderr, "Failed to retrieve CMEM version\n");
    }
    printf("CMEM version = 0x%x\n", version);

    if (CMEM_getBlockAttrs(0, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 0 bounds\n");
    }
    printf("CMEM memory block 0: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    if (CMEM_getBlockAttrs(1, &attrs) == -1) {
        fprintf(stderr, "Failed to retrieve CMEM memory block 1 bounds\n");
    }
    printf("CMEM memory block 1: phys start = 0x%lx, size = 0x%x\n",
           attrs.phys_base, attrs.size);

    testHeap(size, 0);
    testHeap(size, 1);

    testCache(size, 0);
    testCache(size, 1);

    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }

    exit(EXIT_SUCCESS);
}
예제 #3
0
파일: apitest.c 프로젝트: zandrey/ti-ludev
int main(int argc, char *argv[])
{
    size_t size;
    int version;
    CMEM_BlockAttrs attrs;
    int i;
    int c;
    
    non_interactive_flag = FALSE;

    while ((c = getopt(argc, argv, "n")) != -1) {
	switch (c) {
	case 'n':
	    non_interactive_flag = TRUE; 	
	    break;

	default:
	    fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
		    argv[0]);
	    fprintf(stderr,
                    "    -n: non-interactive mode (no ENTER prompts)\n");
	    exit(EXIT_FAILURE);
	}
    }

    if ((argc - optind + 1) != 2) {
	fprintf(stderr, "Usage: %s [-n] <Number of bytes to allocate>\n",
	        argv[0]);
	fprintf(stderr, "    -n: non-interactive mode (no ENTER prompts)\n");
	exit(EXIT_FAILURE);
    }

    errno = 0;
    size = strtol(argv[optind], NULL, 0);

    if (errno) {
	fprintf(stderr, "Bad argument ('%s'), strtol() set errno %d\n",
	        argv[optind], errno);
        exit(EXIT_FAILURE);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Failed to initialize CMEM\n");
        exit(EXIT_FAILURE);
    }

    printf("CMEM initialized.\n");

    version = CMEM_getVersion();
    if (version == -1) {
	fprintf(stderr, "Failed to retrieve CMEM version\n");
        exit(EXIT_FAILURE);
    }
    printf("CMEM version = 0x%x\n", version);

    testMap(size);
    testAllocPhys(size);

    testCMA(size);

    if (CMEM_getNumBlocks(&nblocks)) {
	fprintf(stderr, "Failed to retrieve number of blocks\n");
        exit(EXIT_FAILURE);
    }
    printf("\n# of CMEM blocks (doesn't include possible CMA global 'block'): %d\n", nblocks);

    if (nblocks) {
	for (i = 0; i < nblocks; i++) {
	    if (CMEM_getBlockAttrs(i, &attrs) == -1) {
		fprintf(stderr, "Failed to retrieve CMEM memory block %d bounds\n", i);
	    }
	    else {
		printf("CMEM memory block %d: phys start = %#llx, size = %#llx\n",
		       i, (unsigned long long)attrs.phys_base, attrs.size);
	    }

	    testHeap(size, i);
	    testHeap(size, i);
	    testPools(size, i);
	    testPools(size, i);
	    testCache(size, i);
	}
    }
    else {
	printf("    no physical block found, not performing block-based testing\n");
    }

    /* block 'nblocks' is the special CMEM CMA "block" */
    testPools(size, CMEM_CMABLOCKID);

    printf("\nexiting...\n");
    if (CMEM_exit() < 0) {
        fprintf(stderr, "Failed to finalize the CMEM module\n");
    }
    printf("...test done\n");

    exit(EXIT_SUCCESS);
}