1239922Sgonzo/*-
2239922Sgonzo * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3239922Sgonzo * All rights reserved.
4239922Sgonzo *
5239922Sgonzo * Redistribution and use in source and binary forms, with or without
6239922Sgonzo * modification, are permitted provided that the following conditions
7239922Sgonzo * are met:
8239922Sgonzo * 1. Redistributions of source code must retain the above copyright
9239922Sgonzo *    notice, this list of conditions and the following disclaimer.
10239922Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
11239922Sgonzo *    notice, this list of conditions and the following disclaimer in the
12239922Sgonzo *    documentation and/or other materials provided with the distribution.
13239922Sgonzo *
14239922Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15239922Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16239922Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17239922Sgonzo * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18239922Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19239922Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20239922Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21239922Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22239922Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23239922Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24239922Sgonzo * SUCH DAMAGE.
25239922Sgonzo *
26239922Sgonzo * $FreeBSD$
27239922Sgonzo */
28239922Sgonzo
29239922Sgonzo/*
30239922Sgonzo * Defines for converting physical address to VideoCore bus address and back
31239922Sgonzo */
32239922Sgonzo
33239922Sgonzo#ifndef _BCM2835_VCBUS_H_
34239922Sgonzo#define _BCM2835_VCBUS_H_
35239922Sgonzo
36239922Sgonzo#define	BCM2835_VCBUS_SDRAM_CACHED	0x40000000
37247204Sgonzo#define	BCM2835_VCBUS_IO_BASE		0x7E000000
38239922Sgonzo#define	BCM2835_VCBUS_SDRAM_UNCACHED	0xC0000000
39239922Sgonzo
40247204Sgonzo#define	BCM2835_ARM_IO_BASE		0x20000000
41247204Sgonzo#define	BCM2835_ARM_IO_SIZE		0x02000000
42247204Sgonzo
43239922Sgonzo/*
44239922Sgonzo * Convert physical address to VC bus address. Should be used
45239922Sgonzo * when submitting address over mailbox interface
46239922Sgonzo */
47239922Sgonzo#define	PHYS_TO_VCBUS(pa)	((pa) + BCM2835_VCBUS_SDRAM_CACHED)
48239922Sgonzo
49247204Sgonzo/* Check whether pa bellong top IO window */
50247204Sgonzo#define BCM2835_ARM_IS_IO(pa)	(((pa) >= BCM2835_ARM_IO_BASE) && \
51247204Sgonzo    ((pa) < BCM2835_ARM_IO_BASE + BCM2835_ARM_IO_SIZE))
52247204Sgonzo
53239922Sgonzo/*
54247204Sgonzo * Convert physical address in IO space to VC bus address.
55247204Sgonzo */
56247204Sgonzo#define	IO_TO_VCBUS(pa)		((pa - BCM2835_ARM_IO_BASE) + \
57247204Sgonzo    BCM2835_VCBUS_IO_BASE)
58247204Sgonzo
59247204Sgonzo/*
60239922Sgonzo * Convert address from VC bus space to physical. Should be used
61239922Sgonzo * when address is returned by VC over mailbox interface. e.g.
62239922Sgonzo * framebuffer base
63239922Sgonzo */
64239922Sgonzo#define	VCBUS_TO_PHYS(vca)	((vca) - BCM2835_VCBUS_SDRAM_CACHED)
65239922Sgonzo
66239922Sgonzo#endif /* _BCM2835_VCBUS_H_ */
67