source: mainline/kernel/genarch/src/drivers/bcm2835/mbox.c@ b272c67a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b272c67a was 44186b01, checked in by Beniamino Galvani <b.galvani@…>, 13 years ago

bcm2835: statically allocate framebuffer descriptor

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2013 Beniamino Galvani
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup genarch
29 * @{
30 */
31/**
32 * @file
33 * @brief BCM2835 mailbox communication routines
34 */
35
36#include <mm/km.h>
37#include <typedefs.h>
38#include <genarch/drivers/bcm2835/mbox.h>
39
40static void mbox_write(bcm2835_mbox_t *mbox, uint8_t chan, uint32_t value)
41{
42 while (mbox->status & MBOX_STATUS_FULL) ;
43 mbox->write = MBOX_COMPOSE(chan, value);
44}
45
46static uint32_t mbox_read(bcm2835_mbox_t *mbox, uint8_t chan)
47{
48 uint32_t msg;
49
50 do {
51 while (mbox->status & MBOX_STATUS_EMPTY) ;
52 msg = mbox->read;
53 } while (MBOX_MSG_CHAN(msg) != chan);
54
55 return MBOX_MSG_VALUE(msg);
56}
57
58bool bcm2835_prop_get_memory(uint32_t *base, uint32_t *size)
59{
60 bool ret;
61 MBOX_BUFF_ALLOC(req, mbox_getmem_buf_t);
62
63 req->buf_hdr.size = sizeof(mbox_getmem_buf_t);
64 req->buf_hdr.code = MBOX_PROP_CODE_REQ;
65 req->tag_hdr.tag_id = TAG_GET_ARM_MEMORY;
66 req->tag_hdr.buf_size = sizeof(mbox_tag_getmem_resp_t);
67 req->tag_hdr.val_len = 0;
68 req->zero = 0;
69
70 mbox_write((bcm2835_mbox_t *)BCM2835_MBOX0_ADDR,
71 MBOX_CHAN_PROP_A2V, KA2VCA((uint32_t)req));
72 mbox_read((bcm2835_mbox_t *)BCM2835_MBOX0_ADDR,
73 MBOX_CHAN_PROP_A2V);
74
75 if (req->buf_hdr.code == MBOX_PROP_CODE_RESP_OK) {
76 *base = req->data.base;
77 *size = req->data.size;
78 ret = true;
79 } else {
80 ret = false;
81 }
82
83 return ret;
84}
85
86bool bcm2835_fb_init(fb_properties_t *prop)
87{
88 bcm2835_mbox_t *fb_mbox;
89 bool ret = false;
90 MBOX_BUFF_ALLOC(fb_desc, bcm2835_fb_desc_t);
91
92 fb_mbox = (void *) km_map(BCM2835_MBOX0_ADDR, sizeof(bcm2835_mbox_t),
93 PAGE_NOT_CACHEABLE);
94
95 fb_desc->width = 640;
96 fb_desc->height = 480;
97 fb_desc->virt_width = fb_desc->width;
98 fb_desc->virt_height = fb_desc->height;
99 fb_desc->pitch = 0; /* Set by VC */
100 fb_desc->bpp = 16;
101 fb_desc->x_offset = 0;
102 fb_desc->y_offset = 0;
103 fb_desc->addr = 0; /* Set by VC */
104 fb_desc->size = 0; /* Set by VC */
105
106 mbox_write(fb_mbox, MBOX_CHAN_FB, KA2VCA(fb_desc));
107
108 if (mbox_read(fb_mbox, MBOX_CHAN_FB)) {
109 printf("BCM2835 framebuffer initialization failed\n");
110 goto out;
111 }
112
113 prop->addr = fb_desc->addr;
114 prop->offset = 0;
115 prop->x = fb_desc->width;
116 prop->y = fb_desc->height;
117 prop->scan = fb_desc->pitch;
118 prop->visual = VISUAL_RGB_5_6_5_LE;
119
120 printf("BCM2835 framebuffer at 0x%08x (%dx%d)\n", prop->addr,
121 prop->x, prop->y);
122 ret = true;
123out:
124 km_unmap((uintptr_t)fb_mbox, sizeof(bcm2835_mbox_t));
125 return ret;
126}
127
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.