Ejemplo n.º 1
0
int __prussdrv_memmap_init(void)
{
    int i, fd;
    char hexstring[PRUSS_UIO_PARAM_VAL_LEN];

    if (prussdrv.mmap_fd == 0) {
        for (i = 0; i < NUM_PRU_HOSTIRQS; i++) {
            if (prussdrv.fd[i])
                break;
        }
        if (i == NUM_PRU_HOSTIRQS)
            return -1;
        else
            prussdrv.mmap_fd = prussdrv.fd[i];
    }

    for (i=0; i<UIO_OPEN_TIMEOUT; i++) {
        fd = open(PRUSS_UIO_DRV_PRUSS_BASE, O_RDONLY);
        if (fd >= 0) {
            read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
            prussdrv.pruss_phys_base =
                strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
            close(fd);
            break;
        }
        sleep(1);
    }
    if (i==UIO_OPEN_TIMEOUT) {
        DEBUG_PRINTF("open %s: timeout\n", PRUSS_UIO_DRV_PRUSS_BASE);
        return -2;
    }

    fd = open(PRUSS_UIO_DRV_PRUSS_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.pruss_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -3;

    prussdrv.pru0_dataram_base =
        mmap(0, prussdrv.pruss_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_PRUSS);
    prussdrv.version =
        __pruss_detect_hw_version((unsigned int *) prussdrv.pru0_dataram_base);

    switch (prussdrv.version) {
    case PRUSS_V1:
    {
        DEBUG_PRINTF(PRUSS_V1_STR "\n");
        prussdrv.pru0_dataram_phy_base = AM18XX_DATARAM0_PHYS_BASE;
        prussdrv.pru1_dataram_phy_base = AM18XX_DATARAM1_PHYS_BASE;
        prussdrv.intc_phy_base = AM18XX_INTC_PHYS_BASE;
        prussdrv.pru0_control_phy_base = AM18XX_PRU0CONTROL_PHYS_BASE;
        prussdrv.pru0_debug_phy_base = AM18XX_PRU0DEBUG_PHYS_BASE;
        prussdrv.pru1_control_phy_base = AM18XX_PRU1CONTROL_PHYS_BASE;
        prussdrv.pru1_debug_phy_base = AM18XX_PRU1DEBUG_PHYS_BASE;
        prussdrv.pru0_iram_phy_base = AM18XX_PRU0IRAM_PHYS_BASE;
        prussdrv.pru1_iram_phy_base = AM18XX_PRU1IRAM_PHYS_BASE;
    }
    break;
    case PRUSS_V2:
    {
        DEBUG_PRINTF(PRUSS_V2_STR "\n");
        prussdrv.pru0_dataram_phy_base = AM33XX_DATARAM0_PHYS_BASE;
        prussdrv.pru1_dataram_phy_base = AM33XX_DATARAM1_PHYS_BASE;
        prussdrv.intc_phy_base = AM33XX_INTC_PHYS_BASE;
        prussdrv.pru0_control_phy_base = AM33XX_PRU0CONTROL_PHYS_BASE;
        prussdrv.pru0_debug_phy_base = AM33XX_PRU0DEBUG_PHYS_BASE;
        prussdrv.pru1_control_phy_base = AM33XX_PRU1CONTROL_PHYS_BASE;
        prussdrv.pru1_debug_phy_base = AM33XX_PRU1DEBUG_PHYS_BASE;
        prussdrv.pru0_iram_phy_base = AM33XX_PRU0IRAM_PHYS_BASE;
        prussdrv.pru1_iram_phy_base = AM33XX_PRU1IRAM_PHYS_BASE;
        prussdrv.pruss_sharedram_phy_base =
            AM33XX_PRUSS_SHAREDRAM_BASE;
        prussdrv.pruss_cfg_phy_base = AM33XX_PRUSS_CFG_BASE;
        prussdrv.pruss_uart_phy_base = AM33XX_PRUSS_UART_BASE;
        prussdrv.pruss_iep_phy_base = AM33XX_PRUSS_IEP_BASE;
        prussdrv.pruss_ecap_phy_base = AM33XX_PRUSS_ECAP_BASE;
        prussdrv.pruss_miirt_phy_base = AM33XX_PRUSS_MIIRT_BASE;
        prussdrv.pruss_mdio_phy_base = AM33XX_PRUSS_MDIO_BASE;
    }
    break;
    default:
        DEBUG_PRINTF(PRUSS_UNKNOWN_STR "\n");
    }

#define ADDR_OFFSET(a,o) ((void*) ((char*) (a) + (o)))

    prussdrv.pru1_dataram_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                 prussdrv.pru1_dataram_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.intc_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                     prussdrv.intc_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru0_control_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                 prussdrv.pru0_control_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru0_debug_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                           prussdrv.pru0_debug_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru1_control_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                 prussdrv.pru1_control_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru1_debug_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                           prussdrv.pru1_debug_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru0_iram_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                          prussdrv.pru0_iram_phy_base - prussdrv.pru0_dataram_phy_base);
    prussdrv.pru1_iram_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                          prussdrv.pru1_iram_phy_base - prussdrv.pru0_dataram_phy_base);
    if (prussdrv.version == PRUSS_V2) {
        prussdrv.pruss_sharedram_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                        prussdrv.pruss_sharedram_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_cfg_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                              prussdrv.pruss_cfg_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_uart_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                               prussdrv.pruss_uart_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_iep_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                              prussdrv.pruss_iep_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_ecap_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                               prussdrv.pruss_ecap_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_miirt_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                                prussdrv.pruss_miirt_phy_base - prussdrv.pru0_dataram_phy_base);
        prussdrv.pruss_mdio_base = ADDR_OFFSET(prussdrv.pru0_dataram_base,
                                               prussdrv.pruss_mdio_phy_base - prussdrv.pru0_dataram_phy_base);
    }
#ifndef DISABLE_L3RAM_SUPPORT
    fd = open(PRUSS_UIO_DRV_L3RAM_BASE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.l3ram_phys_base =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -4;


    fd = open(PRUSS_UIO_DRV_L3RAM_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.l3ram_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -5;

    prussdrv.l3ram_base =
        mmap(0, prussdrv.l3ram_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_L3RAM);
#endif

    fd = open(PRUSS_UIO_DRV_EXTRAM_BASE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.extram_phys_base =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -6;

    fd = open(PRUSS_UIO_DRV_EXTRAM_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.extram_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -7;


    prussdrv.extram_base =
        mmap(0, prussdrv.extram_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_EXTRAM);

    return 0;

}
Ejemplo n.º 2
0
int __prussdrv_memmap_init(void)
{
    int i, fd;
    char hexstring[PRUSS_UIO_PARAM_VAL_LEN];

    if (prussdrv.mmap_fd == 0) {
        for (i = 0; i < NUM_PRU_HOSTIRQS; i++) {
            if (prussdrv.fd[i])
                break;
        }
        if (i == NUM_PRU_HOSTIRQS)
            return -1;
        else
            prussdrv.mmap_fd = prussdrv.fd[i];
    }
    fd = open(PRUSS_UIO_DRV_PRUSS_BASE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.pruss_phys_base =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;
    fd = open(PRUSS_UIO_DRV_PRUSS_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.pruss_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;

    prussdrv.pru0_dataram_base =
        mmap(0, prussdrv.pruss_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_PRUSS);
    prussdrv.version =
        __pruss_detect_hw_version(prussdrv.pru0_dataram_base);

    switch (prussdrv.version) {
    case PRUSS_V1:
        {
            printf("AM18XX\n");
            prussdrv.pru0_dataram_phy_base = AM18XX_DATARAM0_PHYS_BASE;
            prussdrv.pru1_dataram_phy_base = AM18XX_DATARAM1_PHYS_BASE;
            prussdrv.intc_phy_base = AM18XX_INTC_PHYS_BASE;
            prussdrv.pru0_control_phy_base = AM18XX_PRU0CONTROL_PHYS_BASE;
            prussdrv.pru0_debug_phy_base = AM18XX_PRU0DEBUG_PHYS_BASE;
            prussdrv.pru1_control_phy_base = AM18XX_PRU1CONTROL_PHYS_BASE;
            prussdrv.pru1_debug_phy_base = AM18XX_PRU1DEBUG_PHYS_BASE;
            prussdrv.pru0_iram_phy_base = AM18XX_PRU0IRAM_PHYS_BASE;
            prussdrv.pru1_iram_phy_base = AM18XX_PRU1IRAM_PHYS_BASE;
        }
        break;
    case PRUSS_V2:
        {
            printf("AM33XX\n");
            prussdrv.pru0_dataram_phy_base = AM33XX_DATARAM0_PHYS_BASE;
            prussdrv.pru1_dataram_phy_base = AM33XX_DATARAM1_PHYS_BASE;
            prussdrv.intc_phy_base = AM33XX_INTC_PHYS_BASE;
            prussdrv.pru0_control_phy_base = AM33XX_PRU0CONTROL_PHYS_BASE;
            prussdrv.pru0_debug_phy_base = AM33XX_PRU0DEBUG_PHYS_BASE;
            prussdrv.pru1_control_phy_base = AM33XX_PRU1CONTROL_PHYS_BASE;
            prussdrv.pru1_debug_phy_base = AM33XX_PRU1DEBUG_PHYS_BASE;
            prussdrv.pru0_iram_phy_base = AM33XX_PRU0IRAM_PHYS_BASE;
            prussdrv.pru1_iram_phy_base = AM33XX_PRU1IRAM_PHYS_BASE;
            prussdrv.pruss_sharedram_phy_base =
                AM33XX_PRUSS_SHAREDRAM_BASE;
            prussdrv.pruss_cfg_phy_base = AM33XX_PRUSS_CFG_BASE;
            prussdrv.pruss_uart_phy_base = AM33XX_PRUSS_UART_BASE;
            prussdrv.pruss_iep_phy_base = AM33XX_PRUSS_IEP_BASE;
            prussdrv.pruss_ecap_phy_base = AM33XX_PRUSS_ECAP_BASE;
            prussdrv.pruss_miirt_phy_base = AM33XX_PRUSS_MIIRT_BASE;
            prussdrv.pruss_mdio_phy_base = AM33XX_PRUSS_MDIO_BASE;
        }
        break;
    default:
        printf("UNKNOWN\n");
    }

    prussdrv.pru1_dataram_base =
        prussdrv.pru0_dataram_base + prussdrv.pru1_dataram_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.intc_base =
        prussdrv.pru0_dataram_base + prussdrv.intc_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru0_control_base =
        prussdrv.pru0_dataram_base + prussdrv.pru0_control_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru0_debug_base =
        prussdrv.pru0_dataram_base + prussdrv.pru0_debug_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru1_control_base =
        prussdrv.pru0_dataram_base + prussdrv.pru1_control_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru1_debug_base =
        prussdrv.pru0_dataram_base + prussdrv.pru1_debug_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru0_iram_base =
        prussdrv.pru0_dataram_base + prussdrv.pru0_iram_phy_base -
        prussdrv.pru0_dataram_phy_base;
    prussdrv.pru1_iram_base =
        prussdrv.pru0_dataram_base + prussdrv.pru1_iram_phy_base -
        prussdrv.pru0_dataram_phy_base;
    if (prussdrv.version == PRUSS_V2) {
        prussdrv.pruss_sharedram_base =
            prussdrv.pru0_dataram_base +
            prussdrv.pruss_sharedram_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_cfg_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_cfg_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_uart_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_uart_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_iep_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_iep_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_ecap_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_ecap_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_miirt_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_miirt_phy_base -
            prussdrv.pru0_dataram_phy_base;
        prussdrv.pruss_mdio_base =
            prussdrv.pru0_dataram_base + prussdrv.pruss_mdio_phy_base -
            prussdrv.pru0_dataram_phy_base;
    }
#ifndef DISABLE_L3RAM_SUPPORT
    fd = open(PRUSS_UIO_DRV_L3RAM_BASE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.l3ram_phys_base =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;


    fd = open(PRUSS_UIO_DRV_L3RAM_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.l3ram_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;

    prussdrv.l3ram_base =
        mmap(0, prussdrv.l3ram_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_L3RAM);
#endif

    fd = open(PRUSS_UIO_DRV_EXTRAM_BASE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.extram_phys_base =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;

    fd = open(PRUSS_UIO_DRV_EXTRAM_SIZE, O_RDONLY);
    if (fd >= 0) {
        read(fd, hexstring, PRUSS_UIO_PARAM_VAL_LEN);
        prussdrv.extram_map_size =
            strtoul(hexstring, NULL, HEXA_DECIMAL_BASE);
        close(fd);
    } else
        return -1;


    prussdrv.extram_base =
        mmap(0, prussdrv.extram_map_size, PROT_READ | PROT_WRITE,
             MAP_SHARED, prussdrv.mmap_fd, PRUSS_UIO_MAP_OFFSET_EXTRAM);

    return 0;

}