Changeset fa239ff2 in rtems


Ignore:
Timestamp:
Jun 19, 2016, 1:41:45 PM (3 years ago)
Author:
Pavel Pisa <ppisa@…>
Branches:
master
Children:
7222a65
Parents:
3e2a3c4
git-author:
Pavel Pisa <ppisa@…> (06/19/16 13:41:45)
git-committer:
Pavel Pisa <ppisa@…> (06/20/16 15:01:19)
Message:

arm/raspberrypi: Ensure that buffers used for VC mail box communication are synchronized through cache.

Location:
c/src/lib/libbsp/arm/raspberrypi/misc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/raspberrypi/misc/vc.c

    r3e2a3c4 rfa239ff2  
    2323#include <bsp/mailbox.h>
    2424#include <bsp/vc.h>
     25#include <libcpu/arm-cp15.h>
    2526#include "vc_defines.h"
    2627
     
    4647}
    4748
     49/*
     50 * When cache is enabled then content of buffer exchanged
     51 * with VideoCore has to be propagated through ARM11/Cortex-A7
     52 * caches
     53 */
     54static inline void
     55bcm2835_mailbox_buffer_flush_and_invalidate(void *buf, size_t size)
     56{
     57  uint32_t sctlr_val;
     58
     59  sctlr_val = arm_cp15_get_control();
     60
     61  arm_cp15_drain_write_buffer();
     62  if (sctlr_val & (ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) {
     63    arm_cp15_drain_write_buffer();
     64    rtems_cache_flush_multiple_data_lines(buf, size);
     65    rtems_cache_invalidate_multiple_data_lines(buf, size);
     66  }
     67}
     68
    4869#define BCM2835_MBOX_VAL_LENGTH_MASK(_val_len) \
    4970  (_val_len&(~BCM2835_MBOX_TAG_VAL_LEN_RESPONSE))
     
    5677    bcm2835_mbox_tag_display_size get_display_size;
    5778    uint32_t end_tag;
    58   }buffer __attribute__((aligned (16)));
     79  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    5980  BCM2835_MBOX_INIT_BUF(&buffer);
    6081  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_display_size,
    6182    BCM2835_MAILBOX_TAG_GET_DISPLAY_SIZE);
     83  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    6284  if (bcm2835_mailbox_send_read_buffer(&buffer))
    6385    return -1;
     
    84106    bcm2835_mbox_tag_get_pitch get_pitch;
    85107    uint32_t end_tag;
    86   } buffer __attribute__((aligned (16)));
     108  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    87109  BCM2835_MBOX_INIT_BUF(&buffer);
    88110  BCM2835_MBOX_INIT_TAG(&buffer.set_display_size,
     
    118140  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_pitch,
    119141    BCM2835_MAILBOX_TAG_GET_PITCH);
     142  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    120143  if (bcm2835_mailbox_send_read_buffer(&buffer))
    121144    return -1;
     
    152175    bcm2835_mbox_tag_get_pitch get_pitch;
    153176    uint32_t end_tag;
    154   }buffer __attribute__((aligned (16)));
     177  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    155178  BCM2835_MBOX_INIT_BUF(&buffer);
    156179  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_pitch,
    157180    BCM2835_MAILBOX_TAG_GET_PITCH);
     181  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    158182  if (bcm2835_mailbox_send_read_buffer(&buffer))
    159183    return -1;
     
    172196    bcm2835_mbox_tag_get_cmd_line get_cmd_line;
    173197    uint32_t end_tag;
    174   }buffer __attribute__((aligned (16)));
     198  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    175199  BCM2835_MBOX_INIT_BUF(&buffer);
    176200  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_cmd_line,
    177201    BCM2835_MAILBOX_TAG_GET_CMD_LINE);
     202  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    178203  if (bcm2835_mailbox_send_read_buffer(&buffer))
    179204    return -1;
     
    197222    bcm2835_mbox_tag_power_state set_power_state;
    198223    uint32_t end_tag;
    199   }buffer __attribute__((aligned (16)));
     224  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    200225  BCM2835_MBOX_INIT_BUF(&buffer);
    201226  BCM2835_MBOX_INIT_TAG(&buffer.set_power_state,
     
    203228  buffer.set_power_state.body.req.dev_id = _entries->dev_id;
    204229  buffer.set_power_state.body.req.state = _entries->state;
     230  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    205231  if (bcm2835_mailbox_send_read_buffer(&buffer))
    206232    return -1;
     
    219245    bcm2835_mbox_tag_get_arm_memory get_arm_memory;
    220246    uint32_t end_tag;
    221   }buffer __attribute__((aligned (16)));
     247  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    222248  BCM2835_MBOX_INIT_BUF(&buffer);
    223249  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_arm_memory,
    224250    BCM2835_MAILBOX_TAG_GET_ARM_MEMORY);
     251  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    225252  if (bcm2835_mailbox_send_read_buffer(&buffer))
    226253    return -1;
     
    239266    bcm2835_mbox_tag_get_vc_memory get_vc_memory;
    240267    uint32_t end_tag;
    241   }buffer __attribute__((aligned (16)));
     268  }buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
    242269  BCM2835_MBOX_INIT_BUF(&buffer);
    243270  BCM2835_MBOX_INIT_TAG_NO_REQ(&buffer.get_vc_memory,
    244271    BCM2835_MAILBOX_TAG_GET_VC_MEMORY);
     272  bcm2835_mailbox_buffer_flush_and_invalidate(&buffer, sizeof(&buffer));
    245273  if (bcm2835_mailbox_send_read_buffer(&buffer))
    246274    return -1;
  • c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h

    r3e2a3c4 rfa239ff2  
    115115    (_t_)->tag_hdr.val_len = 0; \
    116116  }
     117
     118/*
     119 * Mailbox buffers has to be aligned to 16 bytes because
     120 * 4 LSB bits of the BCM2835_MBOX_WRITE and BCM2835_MBOX_READ
     121 * registers are used to pass channel number.
     122 *
     123 * But there is another requirement for buffer allocation
     124 * as well when interface is called after cache is enabled.
     125 * The buffer should not share cache line with another variable
     126 * which can be updated during data exchange with VideoCore.
     127 * If cache is filled to satisfy another variable update
     128 * during VideoCore output is stored into main memory then
     129 * part of received data can be lost.
     130 *
     131 * Cache line length is 64 bytes for RPi2 Cortex-A7 data cache
     132 * so align buffers to this value.
     133 */
     134#define BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE __attribute__((aligned (64)))
    117135
    118136/* Video Core */
     
    245263#define BCM2835_MAILBOX_TAG_SET_TURBO           0x00038009
    246264
     265#define BCM2835_MAILBOX_TAG_GET_DOMAIN_STATE    0x00030030
     266#define BCM2835_MAILBOX_TAG_SET_DOMAIN_STATE    0x00038030
     267
    247268/* Voltage */
    248269#define BCM2835_MAILBOX_VOLTAGE_RESERVED_UVID        0x000000000
Note: See TracChangeset for help on using the changeset viewer.