1/* $OpenBSD: bcm2835_mbox.h,v 1.1 2020/04/19 14:51:52 tobhe Exp $ */ 2 3/* 4 * Copyright (c) 2020 Tobias Heider <tobhe@openbsd.org> 5 * Copyright (c) 2019 Neil Ashford <ashfordneil0@gmail.com> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20/*- 21 * Copyright (c) 2012 The NetBSD Foundation, Inc. 22 * All rights reserved. 23 * 24 * This code is derived from software contributed to The NetBSD Foundation 25 * by Nick Hudson 26 * 27 * Redistribution and use in source and binary forms, with or without 28 * modification, are permitted provided that the following conditions 29 * are met: 30 * 1. Redistributions of source code must retain the above copyright 31 * notice, this list of conditions and the following disclaimer. 32 * 2. Redistributions in binary form must reproduce the above copyright 33 * notice, this list of conditions and the following disclaimer in the 34 * documentation and/or other materials provided with the distribution. 35 * 36 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 37 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 38 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 40 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 41 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 42 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 43 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 44 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 46 * POSSIBILITY OF SUCH DAMAGE. 47 */ 48 49#ifndef BCM2835_MBOX_H 50#define BCM2835_MBOX_H 51 52#define BCMMBOX_NUM_CHANNELS 16 53#define BCMMBOX_CHANNEL_MASK 0xf 54 55/* mailbox 0 (from VC) and mailbox 1 (to VC) */ 56#define BCMMBOX_SIZE 0x80 57 58#define BCMMBOX_READ 0x00 59#define BCMMBOX_WRITE 0x00 60#define BCMMBOX_POLL 0x10 /* read without popping the fifo */ 61#define BCMMBOX_ID 0x14 /* sender ID (bottom two bits) */ 62#define BCMMBOX_STATUS 0x18 /* status */ 63#define BCMMBOX_STATUS_FULL 0x80000000 64#define BCMMBOX_STATUS_EMPTY 0x40000000 65#define BCMMBOX_STATUS_LEVEL 0x400000FF 66#define BCMMBOX_CFG 0x1C /* configuration */ 67#define BCMMBOX_CFG_DATA_IRQ_EN 0x00000001 68#define BCMMBOX_CFG_SPACE_IRQ_EN 0x00000002 69#define BCMMBOX_CFG_EMPTYOP_IRQ_EN 0x00000004 70#define BCMMBOX_CFG_MAIL_CLEAR 0x00000008 71#define BCMMBOX_CFG_DATA_PENDING 0x00000010 72#define BCMMBOX_CFG_SPACE_PENDING 0x00000020 73#define BCMMBOX_CFG_EMPTY_OP_PENDING 0x00000040 74#define BCMMBOX_CFG_E_NO_OWN 0x00000100 75#define BCMMBOX_CFG_E_OVERFLOW 0x00000200 76#define BCMMBOX_CFG_E_UNDERFLOW 0x00000400 77 78#define BCMMBOX0_BASE 0x00 79#define BCMMBOX1_BASE 0x20 80 81#define BCMMBOX0_READ (BCMMBOX0_BASE + BCMMBOX_READ) 82#define BCMMBOX0_WRITE (BCMMBOX0_BASE + BCMMBOX_WRITE) 83#define BCMMBOX0_POLL (BCMMBOX0_BASE + BCMMBOX_POLL) 84#define BCMMBOX0_ID (BCMMBOX0_BASE + BCMMBOX_ID) 85#define BCMMBOX0_STATUS (BCMMBOX0_BASE + BCMMBOX_STATUS) 86#define BCMMBOX0_CFG (BCMMBOX0_BASE + BCMMBOX_READ) 87 88#define BCMMBOX1_READ (BCMMBOX1_BASE + BCMMBOX_READ) 89#define BCMMBOX1_WRITE (BCMMBOX1_BASE + BCMMBOX_WRITE) 90#define BCMMBOX1_POLL (BCMMBOX1_BASE + BCMMBOX_POLL) 91#define BCMMBOX1_ID (BCMMBOX1_BASE + BCMMBOX_ID) 92#define BCMMBOX1_STATUS (BCMMBOX1_BASE + BCMMBOX_STATUS) 93#define BCMMBOX1_CFG (BCMMBOX1_BASE + BCMMBOX_READ) 94 95void bcmmbox_read(uint8_t chan, uint32_t *data); 96void bcmmbox_write(uint8_t chan, uint32_t data); 97 98int bcmmbox_post(uint8_t, void *, size_t, uint32_t *); 99 100#endif /* BCM2835_MBOX_H */ 101