mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-11-16 12:34:45 +00:00
leon,gr1553b: Only align allocated memory. Verify alignment of memory.
Update #4303.
This commit is contained in:
committed by
Daniel Hellstrom
parent
14fcf38891
commit
8004ffb649
@@ -284,6 +284,7 @@ int gr1553bc_list_table_alloc
|
||||
int i, j, minor_cnt, size;
|
||||
unsigned int table;
|
||||
struct gr1553bc_priv *bcpriv = list->bc;
|
||||
int retval = 0;
|
||||
|
||||
/* Free previous allocated descriptor table */
|
||||
gr1553bc_list_table_free(list);
|
||||
@@ -298,8 +299,8 @@ int gr1553bc_list_table_alloc
|
||||
/* Address given in Hardware accessible address, we
|
||||
* convert it into CPU-accessible address.
|
||||
*/
|
||||
list->table_hw = (unsigned int)bdtab_custom & ~0x1;
|
||||
list->_table = bdtab_custom;
|
||||
list->_table = (void*)((unsigned int)bdtab_custom & ~0x1);
|
||||
list->table_hw = (unsigned int)list->_table;
|
||||
drvmgr_translate_check(
|
||||
*bcpriv->pdev,
|
||||
DMAMEM_TO_CPU,
|
||||
@@ -310,16 +311,19 @@ int gr1553bc_list_table_alloc
|
||||
if (bdtab_custom == NULL) {
|
||||
/* Allocate descriptors */
|
||||
list->_table = grlib_malloc(size + (GR1553BC_BD_ALIGN-1));
|
||||
if ( list->_table == NULL )
|
||||
return -1;
|
||||
if ( list->_table == NULL ) {
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
/* 128-bit Alignment required by HW */
|
||||
list->table_cpu =
|
||||
(((unsigned int)list->_table + (GR1553BC_BD_ALIGN-1)) &
|
||||
~(GR1553BC_BD_ALIGN-1));
|
||||
} else {
|
||||
/* Custom address, given in CPU-accessible address */
|
||||
list->_table = bdtab_custom;
|
||||
list->table_cpu = (unsigned int)list->_table;
|
||||
}
|
||||
/* 128-bit Alignment required by HW */
|
||||
list->table_cpu =
|
||||
(((unsigned int)list->_table + (GR1553BC_BD_ALIGN-1)) &
|
||||
~(GR1553BC_BD_ALIGN-1));
|
||||
|
||||
/* We got CPU accessible descriptor table address, now we
|
||||
* translate that into an address that the Hardware can
|
||||
@@ -338,6 +342,12 @@ int gr1553bc_list_table_alloc
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify alignment */
|
||||
if (list->table_hw & (GR1553BC_BD_ALIGN-1)) {
|
||||
retval = -2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Write End-Of-List all over the descriptor table here,
|
||||
* For debugging/safety?
|
||||
*/
|
||||
@@ -359,8 +369,16 @@ int gr1553bc_list_table_alloc
|
||||
table += gr1553bc_minor_table_size(major->minors[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
if (retval) {
|
||||
if (list->_table_custom == NULL && list->_table) {
|
||||
free(list->_table);
|
||||
}
|
||||
list->table_hw = 0;
|
||||
list->table_cpu = 0;
|
||||
list->_table = NULL;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void gr1553bc_list_table_free(struct gr1553bc_list *list)
|
||||
|
||||
@@ -178,6 +178,7 @@ void gr1553bm_close(void *bm)
|
||||
/* Configure the BM driver */
|
||||
int gr1553bm_config(void *bm, struct gr1553bm_config *cfg)
|
||||
{
|
||||
int retval = 0;
|
||||
struct gr1553bm_priv *priv = bm;
|
||||
|
||||
if ( priv->started )
|
||||
@@ -193,12 +194,11 @@ int gr1553bm_config(void *bm, struct gr1553bm_config *cfg)
|
||||
}
|
||||
priv->buffer_size = cfg->buffer_size & ~0x7; /* on 8 byte bounadry */
|
||||
if ((unsigned int)cfg->buffer_custom & 1) {
|
||||
/* Custom Address Given in Remote address. We need
|
||||
* to convert it intoTranslate into Hardware a
|
||||
* hardware accessible address
|
||||
/* Custom address given in remote address. We need
|
||||
* to convert it into a hardware accessible address
|
||||
*/
|
||||
priv->buffer_base_hw = (unsigned int)cfg->buffer_custom & ~1;
|
||||
priv->buffer = cfg->buffer_custom;
|
||||
priv->buffer = (void*)((unsigned int)cfg->buffer_custom & ~1);
|
||||
priv->buffer_base_hw = (unsigned int)priv->buffer;
|
||||
drvmgr_translate_check(
|
||||
*priv->pdev,
|
||||
DMAMEM_TO_CPU,
|
||||
@@ -209,17 +209,19 @@ int gr1553bm_config(void *bm, struct gr1553bm_config *cfg)
|
||||
if (cfg->buffer_custom == NULL) {
|
||||
/* Allocate new buffer dynamically */
|
||||
priv->buffer = grlib_malloc(priv->buffer_size + 8);
|
||||
if (priv->buffer == NULL)
|
||||
return -1;
|
||||
if (priv->buffer == NULL) {
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
/* Align to 8 bytes */
|
||||
priv->buffer_base = ((unsigned int)priv->buffer + (8-1)) & ~(8-1);
|
||||
} else {
|
||||
/* Address given in CPU accessible address, no
|
||||
* translation required.
|
||||
*/
|
||||
priv->buffer = cfg->buffer_custom;
|
||||
priv->buffer_base = (unsigned int)priv->buffer;
|
||||
}
|
||||
/* Align to 16 bytes */
|
||||
priv->buffer_base = ((unsigned int)priv->buffer + (8-1)) &
|
||||
~(8-1);
|
||||
/* Translate address of buffer base into address that Hardware must
|
||||
* use to access the buffer.
|
||||
*/
|
||||
@@ -232,10 +234,25 @@ int gr1553bm_config(void *bm, struct gr1553bm_config *cfg)
|
||||
|
||||
}
|
||||
|
||||
/* Verify alignment */
|
||||
if (priv->buffer_base_hw & (8-1)) {
|
||||
retval = -2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Copy valid config */
|
||||
priv->cfg = *cfg;
|
||||
|
||||
return 0;
|
||||
err:
|
||||
if (retval) {
|
||||
if (cfg->buffer_custom == NULL && priv->buffer) {
|
||||
free(priv->buffer);
|
||||
}
|
||||
priv->buffer_base_hw = (unsigned int)NULL;
|
||||
priv->buffer_base = (unsigned int)NULL;
|
||||
priv->buffer = NULL;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Start logging */
|
||||
|
||||
@@ -195,10 +195,9 @@ static int gr1553rt_bd_alloc(void *rt, struct gr1553rt_sw_bd **bd, int cnt)
|
||||
}
|
||||
|
||||
*bd = &priv->swbds[priv->swbd_free];
|
||||
curr = &priv->swbds[priv->swbd_free];
|
||||
for (i=0; i<cnt; i++) {
|
||||
if ( i == 0) {
|
||||
curr = &priv->swbds[priv->swbd_free];
|
||||
} else {
|
||||
if ( i != 0) {
|
||||
curr = &priv->swbds[curr->this_next];
|
||||
}
|
||||
if ( curr->this_next == 0xffff ) {
|
||||
@@ -772,17 +771,17 @@ void gr1553rt_sw_free(struct gr1553rt_priv *priv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Free dynamically allocated buffers, if any */
|
||||
static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
{
|
||||
int size;
|
||||
int retval = 0;
|
||||
|
||||
/* Allocate Event log */
|
||||
if ((unsigned int)priv->cfg.evlog_buffer & 1) {
|
||||
/* Translate Address from HARDWARE (REMOTE) to CPU-LOCAL */
|
||||
priv->evlog_hw_base = (unsigned int *)
|
||||
priv->evlog_buffer = (void *)
|
||||
((unsigned int)priv->cfg.evlog_buffer & ~0x1);
|
||||
priv->evlog_buffer = priv->cfg.evlog_buffer;
|
||||
priv->evlog_hw_base = (unsigned int*)priv->evlog_buffer;
|
||||
drvmgr_translate_check(
|
||||
*priv->pdev,
|
||||
DMAMEM_TO_CPU,
|
||||
@@ -794,16 +793,19 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
if (priv->cfg.evlog_buffer == NULL) {
|
||||
priv->evlog_buffer = grlib_malloc(
|
||||
priv->cfg.evlog_size * 2);
|
||||
if (priv->evlog_buffer == NULL)
|
||||
return -1;
|
||||
if (priv->evlog_buffer == NULL) {
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
/* Align to SIZE bytes boundary */
|
||||
priv->evlog_cpu_base = (unsigned int *)
|
||||
(((unsigned int)priv->evlog_buffer +
|
||||
(priv->cfg.evlog_size-1)) & ~(priv->cfg.evlog_size-1));
|
||||
} else {
|
||||
/* Addess already CPU-LOCAL */
|
||||
priv->evlog_buffer = priv->cfg.evlog_buffer;
|
||||
priv->evlog_cpu_base = (unsigned int *)priv->evlog_buffer;
|
||||
}
|
||||
/* Align to SIZE bytes boundary */
|
||||
priv->evlog_cpu_base = (unsigned int *)
|
||||
(((unsigned int)priv->evlog_buffer +
|
||||
(priv->cfg.evlog_size-1)) & ~(priv->cfg.evlog_size-1));
|
||||
|
||||
drvmgr_translate_check(
|
||||
*priv->pdev,
|
||||
@@ -813,6 +815,11 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
priv->cfg.evlog_size
|
||||
);
|
||||
}
|
||||
/* Verify alignment */
|
||||
if ((unsigned int)priv->evlog_hw_base & (priv->cfg.evlog_size-1)) {
|
||||
retval = -2;
|
||||
goto err;
|
||||
}
|
||||
priv->evlog_cpu_end = priv->evlog_cpu_base +
|
||||
priv->cfg.evlog_size/sizeof(unsigned int *);
|
||||
|
||||
@@ -821,9 +828,9 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
size = priv->bds_cnt * sizeof(struct gr1553rt_bd);
|
||||
if ((unsigned int)priv->cfg.bd_buffer & 1) {
|
||||
/* Translate Address from HARDWARE (REMOTE) to CPU-LOCAL */
|
||||
priv->bds_hw = (struct gr1553rt_bd *)
|
||||
priv->bd_buffer = (void *)
|
||||
((unsigned int)priv->cfg.bd_buffer & ~0x1);
|
||||
priv->bd_buffer = priv->cfg.bd_buffer;
|
||||
priv->bds_hw = (struct gr1553rt_bd *)priv->bd_buffer;
|
||||
drvmgr_translate_check(
|
||||
*priv->pdev,
|
||||
DMAMEM_TO_CPU,
|
||||
@@ -834,15 +841,18 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
} else {
|
||||
if ( priv->cfg.bd_buffer == NULL ) {
|
||||
priv->bd_buffer = grlib_malloc(size + 0xf);
|
||||
if (priv->bd_buffer == NULL)
|
||||
return -1;
|
||||
if (priv->bd_buffer == NULL) {
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
/* Align to 16 bytes boundary */
|
||||
priv->bds_cpu = (struct gr1553rt_bd *)
|
||||
(((unsigned int)priv->bd_buffer + 0xf) & ~0xf);
|
||||
} else {
|
||||
/* Addess already CPU-LOCAL */
|
||||
priv->bd_buffer = priv->cfg.bd_buffer;
|
||||
priv->bds_cpu = (struct gr1553rt_bd *)priv->bd_buffer;
|
||||
}
|
||||
/* Align to 16 bytes boundary */
|
||||
priv->bds_cpu = (struct gr1553rt_bd *)
|
||||
(((unsigned int)priv->bd_buffer + 0xf) & ~0xf);
|
||||
|
||||
/* Translate from CPU address to hardware address */
|
||||
drvmgr_translate_check(
|
||||
@@ -853,21 +863,28 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
size
|
||||
);
|
||||
}
|
||||
/* Verify alignment */
|
||||
if ((unsigned int)priv->bds_hw & (0xf)) {
|
||||
retval = -2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
#if (RTBD_MAX == 0)
|
||||
/* Allocate software description of */
|
||||
priv->swbds = grlib_malloc(priv->cfg.bd_count * sizeof(*priv->swbds));
|
||||
if ( priv->swbds == NULL ) {
|
||||
return -1;
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Allocate Sub address table */
|
||||
if ((unsigned int)priv->cfg.satab_buffer & 1) {
|
||||
/* Translate Address from HARDWARE (REMOTE) to CPU-LOCAL */
|
||||
priv->sas_hw = (struct gr1553rt_sa *)
|
||||
priv->satab_buffer = (void *)
|
||||
((unsigned int)priv->cfg.satab_buffer & ~0x1);
|
||||
priv->satab_buffer = priv->cfg.satab_buffer;
|
||||
priv->sas_hw = (struct gr1553rt_sa *)priv->satab_buffer;
|
||||
|
||||
drvmgr_translate_check(
|
||||
*priv->pdev,
|
||||
DMAMEM_TO_CPU,
|
||||
@@ -877,16 +894,18 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
} else {
|
||||
if (priv->cfg.satab_buffer == NULL) {
|
||||
priv->satab_buffer = grlib_malloc((16 * 32) * 2);
|
||||
if (priv->satab_buffer == NULL)
|
||||
return -1;
|
||||
if (priv->satab_buffer == NULL) {
|
||||
retval = -1;
|
||||
goto err;
|
||||
}
|
||||
/* Align to 512 bytes boundary */
|
||||
priv->sas_cpu = (struct gr1553rt_sa *)
|
||||
(((unsigned int)priv->satab_buffer + 0x1ff) & ~0x1ff);
|
||||
} else {
|
||||
/* Addess already CPU-LOCAL */
|
||||
priv->satab_buffer = priv->cfg.satab_buffer;
|
||||
priv->sas_cpu = (struct gr1553rt_sa *)priv->satab_buffer;
|
||||
}
|
||||
/* Align to 512 bytes boundary */
|
||||
priv->sas_cpu = (struct gr1553rt_sa *)
|
||||
(((unsigned int)priv->satab_buffer + 0x1ff) &
|
||||
~0x1ff);
|
||||
|
||||
/* Translate Address from CPU-LOCAL to HARDWARE (REMOTE) */
|
||||
drvmgr_translate_check(
|
||||
@@ -896,8 +915,17 @@ static int gr1553rt_sw_alloc(struct gr1553rt_priv *priv)
|
||||
(void **)&priv->sas_hw,
|
||||
16 * 32);
|
||||
}
|
||||
/* Verify alignment */
|
||||
if ((unsigned int)priv->sas_hw & (0x1ff)) {
|
||||
retval = -2;
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
if (retval) {
|
||||
gr1553rt_sw_free(priv);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void gr1553rt_sw_init(struct gr1553rt_priv *priv)
|
||||
@@ -943,7 +971,7 @@ void gr1553rt_sw_init(struct gr1553rt_priv *priv)
|
||||
int gr1553rt_config(void *rt, struct gr1553rt_cfg *cfg)
|
||||
{
|
||||
struct gr1553rt_priv *priv = rt;
|
||||
|
||||
int retval = 0;
|
||||
if ( priv->started )
|
||||
return -1;
|
||||
|
||||
@@ -955,9 +983,9 @@ int gr1553rt_config(void *rt, struct gr1553rt_cfg *cfg)
|
||||
if ( cfg->rtaddress > 30 )
|
||||
return -1;
|
||||
if ( (cfg->evlog_size & (cfg->evlog_size-1)) != 0)
|
||||
return -1; /* SIZE: Not aligned to a power of 2 */
|
||||
return -2; /* SIZE: Not aligned to a power of 2 */
|
||||
if ( ((unsigned int)priv->cfg.evlog_buffer & (cfg->evlog_size-1)) != 0 )
|
||||
return -1; /* Buffer: Not aligned to size */
|
||||
return -2; /* Buffer: Not aligned to size */
|
||||
#if (RTBD_MAX > 0)
|
||||
if ( cfg->bd_count > RTBD_MAX )
|
||||
return -1;
|
||||
@@ -968,8 +996,9 @@ int gr1553rt_config(void *rt, struct gr1553rt_cfg *cfg)
|
||||
|
||||
/*** Adapt to new config ***/
|
||||
|
||||
if ( gr1553rt_sw_alloc(priv) != 0 )
|
||||
return -1;
|
||||
if ( (retval=gr1553rt_sw_alloc(priv)) != 0 ) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
gr1553rt_sw_init(priv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user