Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/smartpqi/smartpqi_mem.c
/*- | /*- | ||||
* Copyright (c) 2018 Microsemi Corporation. | * Copyright (c) 2016-2019 Microsemi Corporation. | ||||
* Copyright (c) 2020 Microchip Technology Inc. and it's subsidiaries. | |||||
* | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
Context not available. | |||||
#include "smartpqi_includes.h" | #include "smartpqi_includes.h" | ||||
MALLOC_DEFINE(M_SMARTPQI, "smartpqi", "Buffers for the smartpqi(4) driver"); | MALLOC_DEFINE(M_SMARTPQI, "smartpqi", "Buffers for the smartpqi driver"); | ||||
/* | /* | ||||
* DMA map load callback function | * DMA map load callback function | ||||
*/ | */ | ||||
static void | static void os_dma_map(void *arg, bus_dma_segment_t *segs, int nseg, int error) | ||||
os_dma_map(void *arg, bus_dma_segment_t *segs, int nseg, int error) | |||||
{ | { | ||||
bus_addr_t *paddr = (bus_addr_t *)arg; | bus_addr_t *paddr = (bus_addr_t *)arg; | ||||
*paddr = segs[0].ds_addr; | *paddr = segs[0].ds_addr; | ||||
} | } | ||||
int os_dma_setup(pqisrc_softstate_t *softs) | |||||
{ | |||||
DBG_FUNC("IN\n"); | |||||
DBG_FUNC("OUT\n"); | |||||
return PQI_STATUS_SUCCESS; | |||||
} | |||||
int os_dma_destroy(pqisrc_softstate_t *softs) | |||||
{ | |||||
DBG_FUNC("IN\n"); | |||||
DBG_FUNC("OUT\n"); | |||||
return PQI_STATUS_SUCCESS; | |||||
} | |||||
void os_update_dma_attributes(pqisrc_softstate_t *softs) | |||||
{ | |||||
DBG_FUNC("IN\n"); | |||||
DBG_FUNC("OUT\n"); | |||||
} | |||||
/* | /* | ||||
* DMA mem resource allocation wrapper function | * DMA mem resource allocation wrapper function | ||||
*/ | */ | ||||
int os_dma_mem_alloc(pqisrc_softstate_t *softs, struct dma_mem *dma_mem) | int os_dma_mem_alloc(pqisrc_softstate_t *softs, struct dma_mem *dma_mem) | ||||
{ | { | ||||
int ret = 0; | int ret = BSD_SUCCESS; | ||||
/* DBG_FUNC("IN\n"); */ | /* DBG_FUNC("IN\n"); */ | ||||
/* Make sure the alignment is at least 4 bytes */ | |||||
ASSERT(dma_mem->align >= 4); | |||||
/* DMA memory needed - allocate it */ | /* DMA memory needed - allocate it */ | ||||
if ((ret = bus_dma_tag_create( | if ((ret = bus_dma_tag_create( | ||||
softs->os_specific.pqi_parent_dmat, /* parent */ | softs->os_specific.pqi_parent_dmat, /* parent */ | ||||
Context not available. | |||||
DBG_ERR("can't allocate DMA tag with error = 0x%x\n", ret); | DBG_ERR("can't allocate DMA tag with error = 0x%x\n", ret); | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
if (!dma_mem->dma_tag) { | |||||
DBG_ERR("dma tag is NULL\n"); | |||||
ret = BSD_FAILURE; | |||||
goto err_out; | |||||
} | |||||
if ((ret = bus_dmamem_alloc(dma_mem->dma_tag, (void **)&dma_mem->virt_addr, | if ((ret = bus_dmamem_alloc(dma_mem->dma_tag, (void **)&dma_mem->virt_addr, | ||||
BUS_DMA_NOWAIT, &dma_mem->dma_map)) != 0) { | BUS_DMA_NOWAIT, &dma_mem->dma_map)) != 0) { | ||||
DBG_ERR("can't allocate DMA memory for required object \ | DBG_ERR("can't allocate DMA memory for required object \ | ||||
Context not available. | |||||
goto err_mem; | goto err_mem; | ||||
} | } | ||||
if((ret = bus_dmamap_load(dma_mem->dma_tag, dma_mem->dma_map, | if((ret = bus_dmamap_load(dma_mem->dma_tag, dma_mem->dma_map, | ||||
dma_mem->virt_addr, dma_mem->size, | dma_mem->virt_addr, dma_mem->size, | ||||
os_dma_map, &dma_mem->dma_addr, 0)) != 0) { | os_dma_map, &dma_mem->dma_addr, 0)) != 0) { | ||||
DBG_ERR("can't load DMA memory for required \ | DBG_ERR("can't load DMA memory for required \ | ||||
Context not available. | |||||
memset(dma_mem->virt_addr, 0, dma_mem->size); | memset(dma_mem->virt_addr, 0, dma_mem->size); | ||||
ret = bsd_error_to_pqi_error(ret); | |||||
/* DBG_FUNC("OUT\n"); */ | /* DBG_FUNC("OUT\n"); */ | ||||
return ret; | return ret; | ||||
err_load: | err_load: | ||||
if(dma_mem->virt_addr) | if(dma_mem->virt_addr) | ||||
bus_dmamem_free(dma_mem->dma_tag, dma_mem->virt_addr, | bus_dmamem_free(dma_mem->dma_tag, dma_mem->virt_addr, | ||||
dma_mem->dma_map); | dma_mem->dma_map); | ||||
err_mem: | err_mem: | ||||
if(dma_mem->dma_tag) | if(dma_mem->dma_tag) | ||||
bus_dma_tag_destroy(dma_mem->dma_tag); | bus_dma_tag_destroy(dma_mem->dma_tag); | ||||
err_out: | err_out: | ||||
DBG_FUNC("failed OUT\n"); | DBG_FUNC("failed OUT\n"); | ||||
ret = bsd_error_to_pqi_error(ret); | |||||
return ret; | return ret; | ||||
} | } | ||||
Context not available. | |||||
{ | { | ||||
void *addr = NULL; | void *addr = NULL; | ||||
/* DBG_FUNC("IN\n"); */ | /* DBG_FUNC("IN\n"); */ | ||||
addr = malloc((unsigned long)size, M_SMARTPQI, | addr = malloc((unsigned long)size, M_SMARTPQI, | ||||
M_NOWAIT | M_ZERO); | M_NOWAIT | M_ZERO); | ||||
/* DBG_FUNC("OUT\n"); */ | /* DBG_FUNC("OUT\n"); */ | ||||
return addr; | return addr; | ||||
} | } | ||||
Context not available. | |||||
if (softs->os_specific.pqi_regs_res0 != NULL) | if (softs->os_specific.pqi_regs_res0 != NULL) | ||||
bus_release_resource(softs->os_specific.pqi_dev, | bus_release_resource(softs->os_specific.pqi_dev, | ||||
SYS_RES_MEMORY, | SYS_RES_MEMORY, | ||||
softs->os_specific.pqi_regs_rid0, | softs->os_specific.pqi_regs_rid0, | ||||
softs->os_specific.pqi_regs_res0); | softs->os_specific.pqi_regs_res0); | ||||
} | } | ||||
Context not available. |