[rtems commit] arm/raspberrypi: Mailbox : Extending functionality

Pavel Pisa ppisa at rtems.org
Sat Aug 27 08:18:47 UTC 2016


Module:    rtems
Branch:    master
Commit:    3c74f4aa4df079b9c7c8583ed89129e93116a632
Changeset: http://git.rtems.org/rtems/commit/?id=3c74f4aa4df079b9c7c8583ed89129e93116a632

Author:    Mudit Jain <muditjain18011995 at gmail.com>
Date:      Fri Aug 26 23:15:04 2016 -0700

arm/raspberrypi: Mailbox : Extending functionality

Adding functionality to get board serial,
power state & clock rate

---

 c/src/lib/libbsp/arm/raspberrypi/include/vc.h      | 17 +++++
 c/src/lib/libbsp/arm/raspberrypi/misc/vc.c         | 78 ++++++++++++++++++++++
 c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h | 35 ++++++++++
 3 files changed, 130 insertions(+)

diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/vc.h b/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
index 00414ff..e863732 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/include/vc.h
@@ -106,6 +106,8 @@ typedef struct {
 #define BCM2835_MAILBOX_POWER_STATE_NODEV ( 1 << 1 )
 int bcm2835_mailbox_set_power_state( bcm2835_set_power_state_entries *_entries );
 
+int bcm2835_mailbox_get_power_state( bcm2835_set_power_state_entries *_entries );
+
 typedef struct {
   uint32_t base;
   size_t size;
@@ -135,6 +137,21 @@ int bcm2835_mailbox_get_board_model( bcm2835_get_board_spec_entries *_entries );
 
 int bcm2835_mailbox_get_board_revision(
   bcm2835_get_board_spec_entries *_entries );
+
+typedef struct {
+  uint64_t board_serial;
+} bcm2835_get_board_serial_entries;
+
+int bcm2835_mailbox_get_board_serial(
+  bcm2835_get_board_serial_entries *_entries );
+
+typedef struct {
+  uint32_t clock_id;
+  uint32_t clock_rate;
+} bcm2835_get_clock_rate_entries;
+
+int bcm2835_mailbox_get_clock_rate(
+  bcm2835_get_clock_rate_entries *_entries );
 /** @} */
 
 #endif /* LIBBSP_ARM_RASPBERRYPI_VC_H */
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
index 2fff70b..249ea1e 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
@@ -242,6 +242,32 @@ int bcm2835_mailbox_get_cmdline( bcm2835_get_cmdline_entries *_entries )
   return 0;
 }
 
+int bcm2835_mailbox_get_power_state( bcm2835_set_power_state_entries *_entries )
+{
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
+    bcm2835_mbox_buf_hdr hdr;
+    bcm2835_mbox_tag_get_power_state get_power_state;
+    uint32_t end_tag;
+    uint32_t padding_reserve[16];
+  } buffer;
+  BCM2835_MBOX_INIT_BUF( &buffer );
+  BCM2835_MBOX_INIT_TAG( &buffer.get_power_state,
+    BCM2835_MAILBOX_TAG_GET_POWER_STATE );
+  buffer.get_power_state.body.req.dev_id = _entries->dev_id;
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+
+  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
+    return -1;
+
+  _entries->dev_id = buffer.get_power_state.body.resp.dev_id;
+  _entries->state = buffer.get_power_state.body.resp.state;
+
+  if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
+    return -2;
+
+  return 0;
+}
+
 int bcm2835_mailbox_set_power_state( bcm2835_set_power_state_entries *_entries )
 {
   struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
@@ -407,3 +433,55 @@ int bcm2835_mailbox_get_board_revision(
 
   return 0;
 }
+
+int bcm2835_mailbox_get_board_serial(
+  bcm2835_get_board_serial_entries *_entries )
+{
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
+    bcm2835_mbox_buf_hdr hdr;
+    bcm2835_mbox_tag_get_board_serial get_board_serial;
+    uint32_t end_tag;
+    uint32_t padding_reserve[16];
+  } buffer;
+  BCM2835_MBOX_INIT_BUF( &buffer );
+  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_board_serial,
+    BCM2835_MAILBOX_TAG_GET_BOARD_SERIAL );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+
+  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
+    return -1;
+
+  _entries->board_serial = buffer.get_board_serial.body.resp.board_serial;
+
+  if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
+    return -2;
+
+  return 0;
+}
+
+int bcm2835_mailbox_get_clock_rate(
+  bcm2835_get_clock_rate_entries *_entries )
+{
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
+    bcm2835_mbox_buf_hdr hdr;
+    bcm2835_mbox_tag_get_clock_rate get_clock_rate;
+    uint32_t end_tag;
+    uint32_t padding_reserve[16];
+  } buffer;
+  BCM2835_MBOX_INIT_BUF( &buffer );
+  BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_clock_rate,
+    BCM2835_MAILBOX_TAG_GET_CLOCK_RATE );
+  buffer.get_clock_rate.body.req.clock_id = _entries->clock_id;
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+
+  if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
+    return -1;
+
+  _entries->clock_id = buffer.get_clock_rate.body.resp.clock_id;
+  _entries->clock_rate = buffer.get_clock_rate.body.resp.clock_rate;
+
+  if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
+    return -2;
+
+  return 0;
+}
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
index bc901b4..9725445 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
@@ -182,6 +182,17 @@ typedef struct {
 
 #define BCM2835_MAILBOX_TAG_GET_BOARD_MAC       0x00010003
 #define BCM2835_MAILBOX_TAG_GET_BOARD_SERIAL    0x00010004
+typedef struct {
+  bcm2835_mbox_tag_hdr tag_hdr;
+  union {
+    struct {
+    } req;
+    struct {
+      uint64_t board_serial;
+    } resp;
+  } body;
+} bcm2835_mbox_tag_get_board_serial;
+
 #define BCM2835_MAILBOX_TAG_GET_ARM_MEMORY      0x00010005
 typedef struct {
   bcm2835_mbox_tag_hdr tag_hdr;
@@ -209,6 +220,18 @@ typedef struct {
 } bcm2835_mbox_tag_get_vc_memory;
 
 #define BCM2835_MAILBOX_TAG_GET_CLOCKS          0x00010007
+typedef struct {
+  bcm2835_mbox_tag_hdr tag_hdr;
+  union {
+    struct {
+      uint32_t clock_id;
+    } req;
+    struct {
+      uint32_t clock_id;
+      uint32_t clock_rate;
+    } resp;
+  } body;
+} bcm2835_mbox_tag_get_clock_rate;
 
 /* Config */
 #define BCM2835_MAILBOX_TAG_GET_CMD_LINE        0x00050001
@@ -238,6 +261,18 @@ typedef struct {
 #define BCM2835_MAILBOX_POWER_UDID_CCP2TX            0x00000008
 
 #define BCM2835_MAILBOX_TAG_GET_POWER_STATE     0x00020001
+typedef struct {
+  bcm2835_mbox_tag_hdr tag_hdr;
+  union {
+    struct {
+      uint32_t dev_id;
+    } req;
+    struct {
+      uint32_t dev_id;
+      uint32_t state;
+    } resp;
+  } body;
+} bcm2835_mbox_tag_get_power_state;
 
 #define BCM2835_MAILBOX_POWER_STATE_RESP_ON       (1 << 0)
 #define BCM2835_MAILBOX_POWER_STATE_RESP_NODEV    (1 << 1)




More information about the vc mailing list