summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArvid Bjorkengren <arvid@gaisler.com>2012-09-25 15:26:00 +0200
committerDaniel Hellstrom <daniel@gaisler.com>2012-10-08 10:46:05 +0200
commitedffbe382b5afa8ec6bf423721ab77941651c859 (patch)
treefe7a746ac40469679871dff9de8e7cd5def58739
parent5ca4618d6b886dfe336e34c3f5ffbc8739e8a48a (diff)
RMAP: Make sure buffers are 64-bit aligned to improve odds of getting a fast memcpy-operation.
-rw-r--r--c/src/lib/libbsp/sparc/shared/spw/grspw.c11
-rw-r--r--c/src/lib/libbsp/sparc/shared/spw/rmap.c11
2 files changed, 14 insertions, 8 deletions
diff --git a/c/src/lib/libbsp/sparc/shared/spw/grspw.c b/c/src/lib/libbsp/sparc/shared/spw/grspw.c
index 001f104c36..c4098b898e 100644
--- a/c/src/lib/libbsp/sparc/shared/spw/grspw.c
+++ b/c/src/lib/libbsp/sparc/shared/spw/grspw.c
@@ -155,6 +155,7 @@ typedef struct {
/* statistics */
spw_stats stat;
+ unsigned int _ptr_rxbuf0;
char *ptr_rxbuf0;
char *ptr_txdbuf0;
char *ptr_txhbuf0;
@@ -567,6 +568,7 @@ int grspw_device_init(GRSPW_DEV *pDev)
pDev->txbufcnt = SPACEWIRE_TXBUFS_NR;
pDev->rxbufcnt = SPACEWIRE_RXBUFS_NR;
+ pDev->_ptr_rxbuf0 = 0;
pDev->ptr_rxbuf0 = 0;
pDev->ptr_txdbuf0 = 0;
pDev->ptr_txhbuf0 = 0;
@@ -662,10 +664,11 @@ static int grspw_buffer_alloc(GRSPW_DEV *pDev)
pDev->ptr_rxbuf0 = pDev->rx_dma_area;
}
} else {
- if (pDev->ptr_rxbuf0) {
- free(pDev->ptr_rxbuf0);
+ if (pDev->_ptr_rxbuf0) {
+ free(pDev->_ptr_rxbuf0);
}
- pDev->ptr_rxbuf0 = (char *) malloc(pDev->rxbufsize * pDev->rxbufcnt);
+ pDev->_ptr_rxbuf0 = (unsigned int) malloc(pDev->rxbufsize * pDev->rxbufcnt+4);
+ pDev->ptr_rxbuf0 = (char *)((pDev->_ptr_rxbuf0+7)&~7);
if ( !pDev->ptr_rxbuf0 )
return 1;
}
@@ -1286,7 +1289,7 @@ static rtems_device_driver grspw_control(
}
/* Save new buffer sizes */
- pDev->rxbufsize = ps->rxsize;
+ pDev->rxbufsize = ((ps->rxsize+7)&~7);
pDev->txdbufsize = ps->txdsize;
pDev->txhbufsize = ps->txhsize;
pDev->config.rxmaxlen = pDev->rxbufsize;
diff --git a/c/src/lib/libbsp/sparc/shared/spw/rmap.c b/c/src/lib/libbsp/sparc/shared/spw/rmap.c
index ef9a3757ad..fede5686a3 100644
--- a/c/src/lib/libbsp/sparc/shared/spw/rmap.c
+++ b/c/src/lib/libbsp/sparc/shared/spw/rmap.c
@@ -79,7 +79,8 @@ struct rmap_priv {
char running; /* 1 is started, 0 if stopped */
unsigned char blocking; /* Blocking mode */
unsigned char tx_pkt_hdr[256+9]; /* Packet header used for transmission, last 9 bytes is for RMW commands */
- unsigned int *rx_pkt_buf; /* RX packet Buffer */
+ unsigned int _rx_pkt_buf; /* RX packet Buffer */
+ unsigned int *rx_pkt_buf; /* RX packet Buffer aligned to 64b*/
unsigned int rx_pkt_buf_len; /* RX packet Buffer length */
struct rmap_spw_pkt rxpkt; /* RX packet */
struct rmap_spw_pkt txpkt; /* TX packet */
@@ -135,12 +136,14 @@ void rmap_init_rxpkt(struct rmap_priv *priv, struct rmap_spw_pkt *pkt)
int rmap_start(struct rmap_priv *priv)
{
if ( priv->running == 0 ) {
- if ( !priv->rx_pkt_buf ) {
+ if ( !priv->_rx_pkt_buf ) {
/* Header length + Data CRC + 4 extra */
priv->rx_pkt_buf_len = priv->config->max_rx_len + 16 + 1 + 4;
- priv->rx_pkt_buf = malloc(priv->rx_pkt_buf_len);
+ priv->_rx_pkt_buf = (unsigned int)malloc(priv->rx_pkt_buf_len+4);
+ priv->rx_pkt_buf = (unsigned int*)((priv->_rx_pkt_buf+7)&~7);
if ( priv->rx_pkt_buf == NULL )
return -1;
+
}
/* Set blocking mode */
@@ -365,7 +368,7 @@ int rmap_build(struct rmap_priv *priv, struct rmap_command *cmd, struct rmap_spw
if ( priv->drv_cap & DRV_CAP_HDR_CRC ) {
options |= PKT_OPTION_HDR_CRC;
} else {
- /* Generate CRC and put it at the end of data buffer, Donät calculate
+ /* Generate CRC and put it at the end of data buffer, Don't calculate
* CRC on Destination Path address.
*/
unsigned char crc;