Home | History | Annotate | Line # | Download | only in broadcom
bcm283x_platform.c revision 1.2.2.1
      1  1.2.2.1  pgoyette /*	$NetBSD: bcm283x_platform.c,v 1.2.2.1 2018/03/22 01:44:42 pgoyette Exp $	*/
      2      1.1     skrll 
      3      1.1     skrll /*-
      4      1.1     skrll  * Copyright (c) 2017 Jared D. McNeill <jmcneill (at) invisible.ca>
      5      1.1     skrll  * All rights reserved.
      6      1.1     skrll  *
      7      1.1     skrll  * Redistribution and use in source and binary forms, with or without
      8      1.1     skrll  * modification, are permitted provided that the following conditions
      9      1.1     skrll  * are met:
     10      1.1     skrll  * 1. Redistributions of source code must retain the above copyright
     11      1.1     skrll  *    notice, this list of conditions and the following disclaimer.
     12      1.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     14      1.1     skrll  *    documentation and/or other materials provided with the distribution.
     15      1.1     skrll  *
     16      1.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17      1.1     skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18      1.1     skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1     skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20      1.1     skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21      1.1     skrll  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22      1.1     skrll  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23      1.1     skrll  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24      1.1     skrll  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25      1.1     skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26      1.1     skrll  * SUCH DAMAGE.
     27      1.1     skrll  */
     28      1.1     skrll 
     29      1.1     skrll #include <sys/cdefs.h>
     30  1.2.2.1  pgoyette __KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.2.2.1 2018/03/22 01:44:42 pgoyette Exp $");
     31      1.1     skrll 
     32      1.1     skrll #include "opt_arm_debug.h"
     33      1.1     skrll #include "opt_bcm283x.h"
     34      1.1     skrll #include "opt_cpuoptions.h"
     35      1.1     skrll #include "opt_ddb.h"
     36      1.1     skrll #include "opt_evbarm_boardtype.h"
     37      1.1     skrll #include "opt_kgdb.h"
     38      1.1     skrll #include "opt_fdt.h"
     39      1.1     skrll #include "opt_rpi.h"
     40      1.1     skrll #include "opt_vcprop.h"
     41      1.1     skrll 
     42      1.1     skrll #include "sdhc.h"
     43      1.1     skrll #include "bcmsdhost.h"
     44      1.1     skrll #include "bcmdwctwo.h"
     45      1.1     skrll #include "bcmspi.h"
     46      1.1     skrll #include "bsciic.h"
     47      1.1     skrll #include "plcom.h"
     48      1.1     skrll #include "com.h"
     49      1.1     skrll #include "genfb.h"
     50      1.1     skrll #include "ukbd.h"
     51      1.1     skrll 
     52      1.1     skrll #include <sys/param.h>
     53      1.1     skrll #include <sys/bus.h>
     54      1.1     skrll #include <sys/cpu.h>
     55      1.1     skrll #include <sys/device.h>
     56      1.1     skrll #include <sys/termios.h>
     57      1.1     skrll 
     58      1.1     skrll #include <net/if_ether.h>
     59      1.1     skrll 
     60      1.1     skrll #include <prop/proplib.h>
     61      1.1     skrll 
     62      1.1     skrll #include <dev/fdt/fdtvar.h>
     63      1.1     skrll 
     64      1.1     skrll #include <uvm/uvm_extern.h>
     65      1.1     skrll 
     66      1.1     skrll #include <machine/bootconfig.h>
     67      1.1     skrll #include <arm/cpufunc.h>
     68      1.1     skrll 
     69      1.1     skrll #include <libfdt.h>
     70      1.1     skrll 
     71      1.1     skrll #include <arm/arm32/machdep.h>
     72      1.1     skrll 
     73      1.1     skrll #include <arm/broadcom/bcm2835reg.h>
     74      1.1     skrll #include <arm/broadcom/bcm2835var.h>
     75      1.1     skrll #include <arm/broadcom/bcm2835_intr.h>
     76      1.1     skrll #include <arm/broadcom/bcm2835_mbox.h>
     77      1.1     skrll #include <arm/broadcom/bcm2835_pmwdogvar.h>
     78      1.1     skrll 
     79      1.1     skrll #include <evbarm/dev/plcomreg.h>
     80      1.1     skrll #include <evbarm/dev/plcomvar.h>
     81      1.1     skrll 
     82      1.1     skrll #include <dev/ic/ns16550reg.h>
     83      1.1     skrll #include <dev/ic/comreg.h>
     84      1.1     skrll 
     85      1.1     skrll #include <evbarm/rpi/vcio.h>
     86      1.1     skrll #include <evbarm/rpi/vcpm.h>
     87      1.1     skrll #include <evbarm/rpi/vcprop.h>
     88      1.1     skrll 
     89      1.1     skrll #include <arm/fdt/arm_fdtvar.h>
     90      1.1     skrll 
     91      1.1     skrll #include <arm/cortex/gtmr_var.h>
     92      1.1     skrll 
     93      1.1     skrll #if NGENFB > 0
     94      1.1     skrll #include <dev/videomode/videomode.h>
     95      1.1     skrll #include <dev/videomode/edidvar.h>
     96      1.1     skrll #include <dev/wscons/wsconsio.h>
     97      1.1     skrll #endif
     98      1.1     skrll 
     99      1.1     skrll #if NUKBD > 0
    100      1.1     skrll #include <dev/usb/ukbdvar.h>
    101      1.1     skrll #endif
    102      1.1     skrll 
    103      1.1     skrll #ifdef DDB
    104      1.1     skrll #include <machine/db_machdep.h>
    105      1.1     skrll #include <ddb/db_sym.h>
    106      1.1     skrll #include <ddb/db_extern.h>
    107      1.1     skrll #endif
    108      1.1     skrll 
    109      1.1     skrll void bcm283x_platform_early_putchar(vaddr_t, paddr_t, char c);
    110      1.1     skrll void bcm2835_platform_early_putchar(char c);
    111      1.1     skrll void bcm2836_platform_early_putchar(char c);
    112      1.1     skrll void bcm2837_platform_early_putchar(char c);
    113      1.1     skrll 
    114      1.1     skrll extern void bcmgenfb_set_console_dev(device_t dev);
    115      1.1     skrll void bcmgenfb_set_ioctl(int(*)(void *, void *, u_long, void *, int, struct lwp *));
    116      1.1     skrll extern void bcmgenfb_ddb_trap_callback(int where);
    117      1.1     skrll static int rpi_ioctl(void *, void *, u_long, void *, int, lwp_t *);
    118      1.1     skrll 
    119      1.1     skrll extern struct bus_space armv7_generic_bs_tag;
    120      1.1     skrll extern struct bus_space armv7_generic_a4x_bs_tag;
    121  1.2.2.1  pgoyette extern struct arm32_bus_dma_tag arm_generic_dma_tag;
    122      1.1     skrll 
    123      1.1     skrll /* Prototypes for all the bus_space structure functions */
    124      1.1     skrll bs_protos(bcm2835);
    125      1.1     skrll bs_protos(bcm2835_a4x);
    126      1.1     skrll bs_protos(armv7_generic);
    127      1.1     skrll bs_protos(armv7_generic_a4x);
    128      1.1     skrll bs_protos(generic);
    129      1.1     skrll bs_protos(generic_armv4);
    130      1.1     skrll bs_protos(a4x);
    131      1.1     skrll bs_protos(bs_notimpl);
    132      1.1     skrll 
    133      1.1     skrll struct arm32_dma_range bcm2835_dma_ranges[] = {
    134      1.1     skrll 	[0] = {
    135      1.1     skrll 		.dr_sysbase = 0,
    136      1.1     skrll 		.dr_busbase = BCM2835_BUSADDR_CACHE_COHERENT,
    137      1.1     skrll 	}
    138      1.1     skrll };
    139      1.1     skrll 
    140      1.1     skrll struct arm32_dma_range bcm2836_dma_ranges[] = {
    141      1.1     skrll 	[0] = {
    142      1.1     skrll 		.dr_sysbase = 0,
    143      1.1     skrll 		.dr_busbase = BCM2835_BUSADDR_CACHE_DIRECT,
    144      1.1     skrll 	}
    145      1.1     skrll };
    146      1.1     skrll 
    147      1.1     skrll 
    148      1.1     skrll #if defined(SOC_BCM2835)
    149      1.1     skrll static const struct pmap_devmap *
    150      1.1     skrll bcm2835_platform_devmap(void)
    151      1.1     skrll {
    152      1.1     skrll 	static const struct pmap_devmap devmap[] = {
    153      1.1     skrll 		DEVMAP_ENTRY(BCM2835_PERIPHERALS_VBASE, BCM2835_PERIPHERALS_BASE,
    154      1.1     skrll 		    BCM2835_PERIPHERALS_SIZE),	/* 16Mb */
    155      1.1     skrll 
    156      1.1     skrll 		DEVMAP_ENTRY_END
    157      1.1     skrll 	};
    158      1.1     skrll 
    159      1.1     skrll 	return devmap;
    160      1.1     skrll }
    161      1.1     skrll #endif
    162      1.1     skrll 
    163      1.1     skrll #if defined(SOC_BCM2836)
    164      1.1     skrll static const struct pmap_devmap *
    165      1.1     skrll bcm2836_platform_devmap(void)
    166      1.1     skrll {
    167      1.1     skrll 	static const struct pmap_devmap devmap[] = {
    168      1.1     skrll 		DEVMAP_ENTRY(BCM2836_PERIPHERALS_VBASE, BCM2836_PERIPHERALS_BASE,
    169      1.1     skrll 		    BCM2835_PERIPHERALS_SIZE),	/* 16Mb */
    170      1.1     skrll 
    171      1.1     skrll 		DEVMAP_ENTRY(BCM2836_ARM_LOCAL_VBASE, BCM2836_ARM_LOCAL_BASE,
    172      1.1     skrll 		    BCM2836_ARM_LOCAL_SIZE),
    173      1.1     skrll 
    174      1.1     skrll 		DEVMAP_ENTRY_END
    175      1.1     skrll 	};
    176      1.1     skrll 
    177      1.1     skrll 	return devmap;
    178      1.1     skrll }
    179      1.1     skrll #endif
    180      1.1     skrll 
    181      1.1     skrll /*
    182      1.1     skrll  * Macros to translate between physical and virtual for a subset of the
    183      1.1     skrll  * kernel address space.  *Not* for general use.
    184      1.1     skrll  */
    185      1.1     skrll 
    186      1.1     skrll #define KERN_VTOPDIFF	KERNEL_BASE_VOFFSET
    187      1.1     skrll #define KERN_VTOPHYS(va) ((paddr_t)((vaddr_t)va - KERN_VTOPDIFF))
    188      1.1     skrll #define KERN_PHYSTOV(pa) ((vaddr_t)((paddr_t)pa + KERN_VTOPDIFF))
    189      1.1     skrll 
    190      1.1     skrll 
    191      1.1     skrll #ifndef RPI_FB_WIDTH
    192      1.1     skrll #define RPI_FB_WIDTH	1280
    193      1.1     skrll #endif
    194      1.1     skrll #ifndef RPI_FB_HEIGHT
    195      1.1     skrll #define RPI_FB_HEIGHT	720
    196      1.1     skrll #endif
    197      1.1     skrll 
    198      1.1     skrll int uart_clk = BCM2835_UART0_CLK;
    199      1.1     skrll int core_clk;
    200      1.1     skrll 
    201      1.1     skrll static struct {
    202      1.1     skrll 	struct vcprop_buffer_hdr	vb_hdr;
    203      1.1     skrll 	struct vcprop_tag_clockrate	vbt_uartclockrate;
    204      1.1     skrll 	struct vcprop_tag_clockrate	vbt_vpuclockrate;
    205      1.1     skrll 	struct vcprop_tag end;
    206      1.1     skrll } vb_uart __cacheline_aligned = {
    207      1.1     skrll 	.vb_hdr = {
    208      1.1     skrll 		.vpb_len = sizeof(vb_uart),
    209      1.1     skrll 		.vpb_rcode = VCPROP_PROCESS_REQUEST,
    210      1.1     skrll 	},
    211      1.1     skrll 	.vbt_uartclockrate = {
    212      1.1     skrll 		.tag = {
    213      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
    214      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_uart.vbt_uartclockrate),
    215      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    216      1.1     skrll 		},
    217      1.1     skrll 		.id = VCPROP_CLK_UART
    218      1.1     skrll 	},
    219      1.1     skrll 	.vbt_vpuclockrate = {
    220      1.1     skrll 		.tag = {
    221      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
    222      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_uart.vbt_vpuclockrate),
    223      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    224      1.1     skrll 		},
    225      1.1     skrll 		.id = VCPROP_CLK_CORE
    226      1.1     skrll 	},
    227      1.1     skrll 	.end = {
    228      1.1     skrll 		.vpt_tag = VCPROPTAG_NULL
    229      1.1     skrll 	}
    230      1.1     skrll };
    231      1.1     skrll 
    232      1.1     skrll static struct {
    233      1.1     skrll 	struct vcprop_buffer_hdr	vb_hdr;
    234      1.1     skrll 	struct vcprop_tag_fwrev		vbt_fwrev;
    235      1.1     skrll 	struct vcprop_tag_boardmodel	vbt_boardmodel;
    236      1.1     skrll 	struct vcprop_tag_boardrev	vbt_boardrev;
    237      1.1     skrll 	struct vcprop_tag_macaddr	vbt_macaddr;
    238      1.1     skrll 	struct vcprop_tag_memory	vbt_memory;
    239      1.1     skrll 	struct vcprop_tag_boardserial	vbt_serial;
    240      1.1     skrll 	struct vcprop_tag_dmachan	vbt_dmachan;
    241      1.1     skrll 	struct vcprop_tag_cmdline	vbt_cmdline;
    242      1.1     skrll 	struct vcprop_tag_clockrate	vbt_emmcclockrate;
    243      1.1     skrll 	struct vcprop_tag_clockrate	vbt_armclockrate;
    244      1.1     skrll 	struct vcprop_tag_clockrate	vbt_vpuclockrate;
    245      1.1     skrll 	struct vcprop_tag end;
    246      1.1     skrll } vb __cacheline_aligned = {
    247      1.1     skrll 	.vb_hdr = {
    248      1.1     skrll 		.vpb_len = sizeof(vb),
    249      1.1     skrll 		.vpb_rcode = VCPROP_PROCESS_REQUEST,
    250      1.1     skrll 	},
    251      1.1     skrll 	.vbt_fwrev = {
    252      1.1     skrll 		.tag = {
    253      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_FIRMWAREREV,
    254      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_fwrev),
    255      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    256      1.1     skrll 		},
    257      1.1     skrll 	},
    258      1.1     skrll 	.vbt_boardmodel = {
    259      1.1     skrll 		.tag = {
    260      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_BOARDMODEL,
    261      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_boardmodel),
    262      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    263      1.1     skrll 		},
    264      1.1     skrll 	},
    265      1.1     skrll 	.vbt_boardrev = {
    266      1.1     skrll 		.tag = {
    267      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_BOARDREVISION,
    268      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_boardrev),
    269      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    270      1.1     skrll 		},
    271      1.1     skrll 	},
    272      1.1     skrll 	.vbt_macaddr = {
    273      1.1     skrll 		.tag = {
    274      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_MACADDRESS,
    275      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_macaddr),
    276      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    277      1.1     skrll 		},
    278      1.1     skrll 	},
    279      1.1     skrll 	.vbt_memory = {
    280      1.1     skrll 		.tag = {
    281      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_ARMMEMORY,
    282      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_memory),
    283      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    284      1.1     skrll 		},
    285      1.1     skrll 	},
    286      1.1     skrll 	.vbt_serial = {
    287      1.1     skrll 		.tag = {
    288      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_BOARDSERIAL,
    289      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_serial),
    290      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    291      1.1     skrll 		},
    292      1.1     skrll 	},
    293      1.1     skrll 	.vbt_dmachan = {
    294      1.1     skrll 		.tag = {
    295      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_DMACHAN,
    296      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_dmachan),
    297      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    298      1.1     skrll 		},
    299      1.1     skrll 	},
    300      1.1     skrll 	.vbt_cmdline = {
    301      1.1     skrll 		.tag = {
    302      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CMDLINE,
    303      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_cmdline),
    304      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    305      1.1     skrll 		},
    306      1.1     skrll 	},
    307      1.1     skrll 	.vbt_emmcclockrate = {
    308      1.1     skrll 		.tag = {
    309      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
    310      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_emmcclockrate),
    311      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    312      1.1     skrll 		},
    313      1.1     skrll 		.id = VCPROP_CLK_EMMC
    314      1.1     skrll 	},
    315      1.1     skrll 	.vbt_armclockrate = {
    316      1.1     skrll 		.tag = {
    317      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
    318      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_armclockrate),
    319      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    320      1.1     skrll 		},
    321      1.1     skrll 		.id = VCPROP_CLK_ARM
    322      1.1     skrll 	},
    323      1.1     skrll 	.vbt_vpuclockrate = {
    324      1.1     skrll 		.tag = {
    325      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_CLOCKRATE,
    326      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb.vbt_vpuclockrate),
    327      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST
    328      1.1     skrll 		},
    329      1.1     skrll 		.id = VCPROP_CLK_CORE
    330      1.1     skrll 	},
    331      1.1     skrll 	.end = {
    332      1.1     skrll 		.vpt_tag = VCPROPTAG_NULL
    333      1.1     skrll 	}
    334      1.1     skrll };
    335      1.1     skrll 
    336      1.1     skrll #if NGENFB > 0
    337      1.1     skrll static struct {
    338      1.1     skrll 	struct vcprop_buffer_hdr	vb_hdr;
    339      1.1     skrll 	struct vcprop_tag_edidblock	vbt_edid;
    340      1.1     skrll 	struct vcprop_tag end;
    341      1.1     skrll } vb_edid __cacheline_aligned = {
    342      1.1     skrll 	.vb_hdr = {
    343      1.1     skrll 		.vpb_len = sizeof(vb_edid),
    344      1.1     skrll 		.vpb_rcode = VCPROP_PROCESS_REQUEST,
    345      1.1     skrll 	},
    346      1.1     skrll 	.vbt_edid = {
    347      1.1     skrll 		.tag = {
    348      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_EDID_BLOCK,
    349      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_edid.vbt_edid),
    350      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    351      1.1     skrll 		},
    352      1.1     skrll 		.blockno = 0,
    353      1.1     skrll 	},
    354      1.1     skrll 	.end = {
    355      1.1     skrll 		.vpt_tag = VCPROPTAG_NULL
    356      1.1     skrll 	}
    357      1.1     skrll };
    358      1.1     skrll 
    359      1.1     skrll static struct {
    360      1.1     skrll 	struct vcprop_buffer_hdr	vb_hdr;
    361      1.1     skrll 	struct vcprop_tag_fbres		vbt_res;
    362      1.1     skrll 	struct vcprop_tag_fbres		vbt_vres;
    363      1.1     skrll 	struct vcprop_tag_fbdepth	vbt_depth;
    364      1.1     skrll 	struct vcprop_tag_fbalpha	vbt_alpha;
    365      1.1     skrll 	struct vcprop_tag_allocbuf	vbt_allocbuf;
    366      1.1     skrll 	struct vcprop_tag_blankscreen	vbt_blank;
    367      1.1     skrll 	struct vcprop_tag_fbpitch	vbt_pitch;
    368      1.1     skrll 	struct vcprop_tag end;
    369      1.1     skrll } vb_setfb __cacheline_aligned = {
    370      1.1     skrll 	.vb_hdr = {
    371      1.1     skrll 		.vpb_len = sizeof(vb_setfb),
    372      1.1     skrll 		.vpb_rcode = VCPROP_PROCESS_REQUEST,
    373      1.1     skrll 	},
    374      1.1     skrll 	.vbt_res = {
    375      1.1     skrll 		.tag = {
    376      1.1     skrll 			.vpt_tag = VCPROPTAG_SET_FB_RES,
    377      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_res),
    378      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    379      1.1     skrll 		},
    380      1.1     skrll 		.width = 0,
    381      1.1     skrll 		.height = 0,
    382      1.1     skrll 	},
    383      1.1     skrll 	.vbt_vres = {
    384      1.1     skrll 		.tag = {
    385      1.1     skrll 			.vpt_tag = VCPROPTAG_SET_FB_VRES,
    386      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_vres),
    387      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    388      1.1     skrll 		},
    389      1.1     skrll 		.width = 0,
    390      1.1     skrll 		.height = 0,
    391      1.1     skrll 	},
    392      1.1     skrll 	.vbt_depth = {
    393      1.1     skrll 		.tag = {
    394      1.1     skrll 			.vpt_tag = VCPROPTAG_SET_FB_DEPTH,
    395      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_depth),
    396      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    397      1.1     skrll 		},
    398      1.1     skrll 		.bpp = 32,
    399      1.1     skrll 	},
    400      1.1     skrll 	.vbt_alpha = {
    401      1.1     skrll 		.tag = {
    402      1.1     skrll 			.vpt_tag = VCPROPTAG_SET_FB_ALPHA_MODE,
    403      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_alpha),
    404      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    405      1.1     skrll 		},
    406      1.1     skrll 		.state = VCPROP_ALPHA_IGNORED,
    407      1.1     skrll 	},
    408      1.1     skrll 	.vbt_allocbuf = {
    409      1.1     skrll 		.tag = {
    410      1.1     skrll 			.vpt_tag = VCPROPTAG_ALLOCATE_BUFFER,
    411      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_allocbuf),
    412      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    413      1.1     skrll 		},
    414      1.1     skrll 		.address = PAGE_SIZE,	/* alignment */
    415      1.1     skrll 	},
    416      1.1     skrll 	.vbt_blank = {
    417      1.1     skrll 		.tag = {
    418      1.1     skrll 			.vpt_tag = VCPROPTAG_BLANK_SCREEN,
    419      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_blank),
    420      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    421      1.1     skrll 		},
    422      1.1     skrll 		.state = VCPROP_BLANK_OFF,
    423      1.1     skrll 	},
    424      1.1     skrll 	.vbt_pitch = {
    425      1.1     skrll 		.tag = {
    426      1.1     skrll 			.vpt_tag = VCPROPTAG_GET_FB_PITCH,
    427      1.1     skrll 			.vpt_len = VCPROPTAG_LEN(vb_setfb.vbt_pitch),
    428      1.1     skrll 			.vpt_rcode = VCPROPTAG_REQUEST,
    429      1.1     skrll 		},
    430      1.1     skrll 	},
    431      1.1     skrll 	.end = {
    432      1.1     skrll 		.vpt_tag = VCPROPTAG_NULL,
    433      1.1     skrll 	},
    434      1.1     skrll };
    435      1.1     skrll 
    436      1.1     skrll #endif
    437      1.1     skrll 
    438      1.1     skrll static int rpi_video_on = WSDISPLAYIO_VIDEO_ON;
    439      1.1     skrll 
    440      1.1     skrll #if defined(RPI_HWCURSOR)
    441      1.1     skrll #define CURSOR_BITMAP_SIZE	(64 * 8)
    442      1.1     skrll #define CURSOR_ARGB_SIZE	(64 * 64 * 4)
    443      1.1     skrll static uint32_t hcursor = 0;
    444      1.1     skrll static bus_addr_t pcursor = 0;
    445      1.1     skrll static uint32_t *cmem = NULL;
    446      1.1     skrll static int cursor_x = 0, cursor_y = 0, hot_x = 0, hot_y = 0, cursor_on = 0;
    447      1.1     skrll static uint32_t cursor_cmap[4];
    448      1.1     skrll static uint8_t cursor_mask[8 * 64], cursor_bitmap[8 * 64];
    449      1.1     skrll #endif
    450      1.1     skrll 
    451      1.1     skrll u_int
    452      1.1     skrll bcm283x_clk_get_rate_uart(void)
    453      1.1     skrll {
    454      1.1     skrll 
    455      1.1     skrll 	if (vcprop_tag_success_p(&vb_uart.vbt_uartclockrate.tag))
    456      1.1     skrll 		return vb_uart.vbt_uartclockrate.rate;
    457      1.1     skrll 	return 0;
    458      1.1     skrll }
    459      1.1     skrll 
    460      1.1     skrll u_int
    461      1.1     skrll bcm283x_clk_get_rate_vpu(void)
    462      1.1     skrll {
    463      1.1     skrll 
    464      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_vpuclockrate.tag) &&
    465      1.1     skrll 	    vb.vbt_vpuclockrate.rate > 0) {
    466      1.1     skrll 		return vb.vbt_vpuclockrate.rate;
    467      1.1     skrll 	}
    468      1.1     skrll 	return 0;
    469      1.1     skrll }
    470      1.1     skrll 
    471      1.1     skrll u_int
    472      1.1     skrll bcm283x_clk_get_rate_emmc(void)
    473      1.1     skrll {
    474      1.1     skrll 
    475      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_emmcclockrate.tag) &&
    476      1.1     skrll 	    vb.vbt_emmcclockrate.rate > 0) {
    477      1.1     skrll 		return vb.vbt_emmcclockrate.rate;
    478      1.1     skrll 	}
    479      1.1     skrll 	return 0;
    480      1.1     skrll }
    481      1.1     skrll 
    482      1.1     skrll 
    483      1.1     skrll 
    484      1.1     skrll static void
    485      1.1     skrll bcm283x_uartinit(bus_space_tag_t iot, bus_space_handle_t ioh)
    486      1.1     skrll {
    487      1.1     skrll 	uint32_t res;
    488      1.1     skrll 
    489      1.1     skrll 	bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC,
    490      1.1     skrll 	    KERN_VTOPHYS(&vb_uart));
    491      1.1     skrll 
    492      1.1     skrll 	bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res);
    493      1.1     skrll 
    494      1.1     skrll 	cpu_dcache_inv_range((vaddr_t)&vb_uart, sizeof(vb_uart));
    495      1.1     skrll 
    496      1.1     skrll 	if (vcprop_tag_success_p(&vb_uart.vbt_uartclockrate.tag))
    497      1.1     skrll 		uart_clk = vb_uart.vbt_uartclockrate.rate;
    498      1.1     skrll 	if (vcprop_tag_success_p(&vb_uart.vbt_vpuclockrate.tag))
    499      1.1     skrll 		core_clk = vb_uart.vbt_vpuclockrate.rate;
    500      1.1     skrll }
    501      1.1     skrll 
    502      1.1     skrll #if defined(SOC_BCM2835)
    503      1.1     skrll static void
    504      1.1     skrll bcm2835_uartinit(void)
    505      1.1     skrll {
    506      1.1     skrll 	const paddr_t pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
    507      1.1     skrll 	const bus_space_tag_t iot = &bcm2835_bs_tag;
    508      1.1     skrll 	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(pa);
    509      1.1     skrll 
    510      1.1     skrll 	bcm283x_uartinit(iot, ioh);
    511      1.1     skrll }
    512      1.1     skrll #endif
    513      1.1     skrll 
    514      1.1     skrll #if defined(SOC_BCM2836)
    515      1.1     skrll static void
    516      1.1     skrll bcm2836_uartinit(void)
    517      1.1     skrll {
    518      1.1     skrll 	const paddr_t pa = BCM2836_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
    519      1.1     skrll 	const bus_space_tag_t iot = &bcm2836_bs_tag;
    520      1.1     skrll 	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(pa);
    521      1.1     skrll 
    522      1.1     skrll 	bcm283x_uartinit(iot, ioh);
    523      1.1     skrll }
    524      1.1     skrll #endif
    525      1.1     skrll 
    526      1.1     skrll #define	BCM283x_MINIMUM_SPLIT	(128U * 1024 * 1024)
    527      1.1     skrll 
    528      1.1     skrll static size_t bcm283x_memorysize;
    529      1.1     skrll 
    530      1.1     skrll static void
    531      1.1     skrll bcm283x_bootparams(bus_space_tag_t iot, bus_space_handle_t ioh)
    532      1.1     skrll {
    533      1.1     skrll 	uint32_t res;
    534      1.1     skrll 
    535      1.1     skrll 	bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANPM, (
    536      1.1     skrll #if (NSDHC > 0)
    537      1.1     skrll 	    (1 << VCPM_POWER_SDCARD) |
    538      1.1     skrll #endif
    539      1.1     skrll #if (NPLCOM > 0)
    540      1.1     skrll 	    (1 << VCPM_POWER_UART0) |
    541      1.1     skrll #endif
    542      1.1     skrll #if (NBCMDWCTWO > 0)
    543      1.1     skrll 	    (1 << VCPM_POWER_USB) |
    544      1.1     skrll #endif
    545      1.1     skrll #if (NBSCIIC > 0)
    546      1.1     skrll 	    (1 << VCPM_POWER_I2C0) | (1 << VCPM_POWER_I2C1) |
    547      1.1     skrll 	/*  (1 << VCPM_POWER_I2C2) | */
    548      1.1     skrll #endif
    549      1.1     skrll #if (NBCMSPI > 0)
    550      1.1     skrll 	    (1 << VCPM_POWER_SPI) |
    551      1.1     skrll #endif
    552      1.1     skrll 	    0) << 4);
    553      1.1     skrll 
    554      1.1     skrll 	bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC, KERN_VTOPHYS(&vb));
    555      1.1     skrll 
    556      1.1     skrll 	bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res);
    557      1.1     skrll 
    558      1.1     skrll 	cpu_dcache_inv_range((vaddr_t)&vb, sizeof(vb));
    559      1.1     skrll 
    560      1.1     skrll 	if (!vcprop_buffer_success_p(&vb.vb_hdr)) {
    561      1.1     skrll 		bootconfig.dramblocks = 1;
    562      1.1     skrll 		bootconfig.dram[0].address = 0x0;
    563      1.1     skrll 		bootconfig.dram[0].pages = atop(BCM283x_MINIMUM_SPLIT);
    564      1.1     skrll 		return;
    565      1.1     skrll 	}
    566      1.1     skrll 
    567      1.1     skrll 	struct vcprop_tag_memory *vptp_mem = &vb.vbt_memory;
    568      1.1     skrll 	if (vcprop_tag_success_p(&vptp_mem->tag)) {
    569      1.1     skrll 		size_t n = vcprop_tag_resplen(&vptp_mem->tag) /
    570      1.1     skrll 		    sizeof(struct vcprop_memory);
    571      1.1     skrll 
    572      1.1     skrll 		bcm283x_memorysize = 0;
    573      1.1     skrll 		bootconfig.dramblocks = 0;
    574      1.1     skrll 
    575      1.1     skrll 		for (int i = 0; i < n && i < DRAM_BLOCKS; i++) {
    576      1.1     skrll 			bootconfig.dram[i].address = vptp_mem->mem[i].base;
    577      1.1     skrll 			bootconfig.dram[i].pages = atop(vptp_mem->mem[i].size);
    578      1.1     skrll 			bootconfig.dramblocks++;
    579      1.1     skrll 
    580      1.1     skrll 			bcm283x_memorysize += vptp_mem->mem[i].size;
    581      1.1     skrll 		}
    582      1.1     skrll 	}
    583      1.1     skrll 
    584      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_armclockrate.tag))
    585      1.1     skrll 		curcpu()->ci_data.cpu_cc_freq = vb.vbt_armclockrate.rate;
    586      1.1     skrll 
    587      1.1     skrll #ifdef VERBOSE_INIT_ARM
    588      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_memory.tag)) {
    589      1.1     skrll 		printf("%s: memory size  %d\n", __func__,
    590      1.1     skrll 		    vb.vbt_armclockrate.rate);
    591      1.1     skrll 	}
    592      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_armclockrate.tag))
    593      1.1     skrll 		printf("%s: arm clock    %d\n", __func__,
    594      1.1     skrll 		    vb.vbt_armclockrate.rate);
    595      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_fwrev.tag))
    596      1.1     skrll 		printf("%s: firmware rev %x\n", __func__,
    597      1.1     skrll 		    vb.vbt_fwrev.rev);
    598      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_boardmodel.tag))
    599      1.1     skrll 		printf("%s: board model  %x\n", __func__,
    600      1.1     skrll 		    vb.vbt_boardmodel.model);
    601      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_macaddr.tag))
    602      1.1     skrll 		printf("%s: mac-address  %llx\n", __func__,
    603      1.1     skrll 		    vb.vbt_macaddr.addr);
    604      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_boardrev.tag))
    605      1.1     skrll 		printf("%s: board rev    %x\n", __func__,
    606      1.1     skrll 		    vb.vbt_boardrev.rev);
    607      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_serial.tag))
    608      1.1     skrll 		printf("%s: board serial %llx\n", __func__,
    609      1.1     skrll 		    vb.vbt_serial.sn);
    610      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_dmachan.tag))
    611      1.1     skrll 		printf("%s: DMA channel mask 0x%08x\n", __func__,
    612      1.1     skrll 		    vb.vbt_dmachan.mask);
    613      1.1     skrll 
    614      1.1     skrll 	if (vcprop_tag_success_p(&vb.vbt_cmdline.tag))
    615      1.1     skrll 		printf("%s: cmdline      %s\n", __func__,
    616      1.1     skrll 		    vb.vbt_cmdline.cmdline);
    617      1.1     skrll #endif
    618      1.1     skrll }
    619      1.1     skrll 
    620      1.1     skrll #if defined(SOC_BCM2835)
    621      1.1     skrll static void
    622      1.1     skrll bcm2835_bootparams(void)
    623      1.1     skrll {
    624      1.1     skrll 	const paddr_t pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
    625      1.1     skrll 	const bus_space_tag_t iot = &bcm2835_bs_tag;
    626      1.1     skrll 	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(pa);
    627      1.1     skrll 
    628      1.1     skrll 	bcm283x_bootparams(iot, ioh);
    629      1.1     skrll }
    630      1.1     skrll #endif
    631      1.1     skrll 
    632      1.1     skrll #if defined(SOC_BCM2836)
    633      1.1     skrll static void
    634      1.1     skrll bcm2836_bootparams(void)
    635      1.1     skrll {
    636      1.1     skrll 	const paddr_t pa = BCM2836_PERIPHERALS_BUS_TO_PHYS(BCM2835_ARMMBOX_BASE);
    637      1.1     skrll 	const bus_space_tag_t iot = &bcm2836_bs_tag;
    638      1.1     skrll 	const bus_space_handle_t ioh = BCM2835_IOPHYSTOVIRT(pa);
    639      1.1     skrll 
    640      1.1     skrll 	bcm283x_bootparams(iot, ioh);
    641      1.1     skrll }
    642      1.1     skrll 
    643      1.1     skrll static void
    644      1.1     skrll bcm2836_bootstrap(void)
    645      1.1     skrll {
    646      1.1     skrll 	arm_cpu_max = 4;
    647      1.1     skrll 	extern int cortex_mmuinfo;
    648      1.1     skrll 
    649      1.1     skrll 	cortex_mmuinfo = armreg_ttbr_read();
    650      1.1     skrll #ifdef VERBOSE_INIT_ARM
    651      1.1     skrll 	printf("%s: cortex_mmuinfo %x\n", __func__, cortex_mmuinfo);
    652      1.1     skrll #endif
    653      1.1     skrll 
    654      1.1     skrll 	extern void cortex_mpstart(void);
    655      1.1     skrll 
    656      1.1     skrll 	for (size_t i = 1; i < arm_cpu_max; i++) {
    657      1.1     skrll 		bus_space_tag_t iot = &bcm2836_bs_tag;
    658      1.1     skrll 		bus_space_handle_t ioh = BCM2836_ARM_LOCAL_VBASE;
    659      1.1     skrll 
    660      1.1     skrll 		bus_space_write_4(iot, ioh,
    661      1.1     skrll 		    BCM2836_LOCAL_MAILBOX3_SETN(i),
    662      1.1     skrll 		    (uint32_t)cortex_mpstart);
    663      1.1     skrll 	}
    664      1.1     skrll 
    665      1.1     skrll 	/* Wake up AP in case firmware has placed it in WFE state */
    666      1.1     skrll 	__asm __volatile("sev" ::: "memory");
    667      1.1     skrll 
    668      1.1     skrll 	for (int loop = 0; loop < 16; loop++) {
    669      1.1     skrll 		if (arm_cpu_hatched == __BITS(arm_cpu_max - 1, 1))
    670      1.1     skrll 			break;
    671      1.1     skrll 		gtmr_delay(10000);
    672      1.1     skrll 	}
    673      1.1     skrll 
    674      1.1     skrll 	for (size_t i = 1; i < arm_cpu_max; i++) {
    675      1.1     skrll 		if ((arm_cpu_hatched & (1 << i)) == 0) {
    676      1.1     skrll 			printf("%s: warning: cpu%zu failed to hatch\n",
    677      1.1     skrll 			    __func__, i);
    678      1.1     skrll 		}
    679      1.1     skrll 	}
    680      1.1     skrll }
    681      1.1     skrll 
    682      1.1     skrll #endif	/* SOC_BCM2836 */
    683      1.1     skrll 
    684      1.1     skrll #if NGENFB > 0
    685      1.1     skrll static bool
    686      1.1     skrll rpi_fb_parse_mode(const char *s, uint32_t *pwidth, uint32_t *pheight)
    687      1.1     skrll {
    688      1.1     skrll 	char *x;
    689      1.1     skrll 
    690      1.1     skrll 	if (strncmp(s, "disable", 7) == 0)
    691      1.1     skrll 		return false;
    692      1.1     skrll 
    693      1.1     skrll 	x = strchr(s, 'x');
    694      1.1     skrll 	if (x) {
    695      1.1     skrll 		*pwidth = strtoul(s, NULL, 10);
    696      1.1     skrll 		*pheight = strtoul(x + 1, NULL, 10);
    697      1.1     skrll 	}
    698      1.1     skrll 
    699      1.1     skrll 	return true;
    700      1.1     skrll }
    701      1.1     skrll 
    702      1.1     skrll static bool
    703      1.1     skrll rpi_fb_get_edid_mode(uint32_t *pwidth, uint32_t *pheight)
    704      1.1     skrll {
    705      1.1     skrll 	struct edid_info ei;
    706      1.1     skrll 	uint8_t edid_data[1024];
    707      1.1     skrll 	uint32_t res;
    708      1.1     skrll 	int error;
    709      1.1     skrll 
    710      1.1     skrll 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_edid,
    711      1.1     skrll 	    sizeof(vb_edid), &res);
    712      1.1     skrll 	if (error) {
    713      1.1     skrll 		printf("%s: mbox request failed (%d)\n", __func__, error);
    714      1.1     skrll 		return false;
    715      1.1     skrll 	}
    716      1.1     skrll 
    717      1.1     skrll 	if (!vcprop_buffer_success_p(&vb_edid.vb_hdr) ||
    718      1.1     skrll 	    !vcprop_tag_success_p(&vb_edid.vbt_edid.tag) ||
    719      1.1     skrll 	    vb_edid.vbt_edid.status != 0)
    720      1.1     skrll 		return false;
    721      1.1     skrll 
    722      1.1     skrll 	memset(edid_data, 0, sizeof(edid_data));
    723      1.1     skrll 	memcpy(edid_data, vb_edid.vbt_edid.data,
    724      1.1     skrll 	    sizeof(vb_edid.vbt_edid.data));
    725      1.1     skrll 	edid_parse(edid_data, &ei);
    726      1.1     skrll #ifdef VERBOSE_INIT_ARM
    727      1.1     skrll 	edid_print(&ei);
    728      1.1     skrll #endif
    729      1.1     skrll 
    730      1.1     skrll 	if (ei.edid_preferred_mode) {
    731      1.1     skrll 		*pwidth = ei.edid_preferred_mode->hdisplay;
    732      1.1     skrll 		*pheight = ei.edid_preferred_mode->vdisplay;
    733      1.1     skrll 	}
    734      1.1     skrll 
    735      1.1     skrll 	return true;
    736      1.1     skrll }
    737      1.1     skrll 
    738      1.1     skrll /*
    739      1.1     skrll  * Initialize framebuffer console.
    740      1.1     skrll  *
    741      1.1     skrll  * Some notes about boot parameters:
    742      1.1     skrll  *  - If "fb=disable" is present, ignore framebuffer completely.
    743      1.1     skrll  *  - If "fb=<width>x<height> is present, use the specified mode.
    744      1.1     skrll  *  - If "console=fb" is present, attach framebuffer to console.
    745      1.1     skrll  */
    746      1.1     skrll static bool
    747      1.1     skrll rpi_fb_init(prop_dictionary_t dict, void *aux)
    748      1.1     skrll {
    749      1.1     skrll 	uint32_t width = 0, height = 0;
    750      1.1     skrll 	uint32_t res;
    751      1.1     skrll 	char *ptr;
    752      1.1     skrll 	int integer;
    753      1.1     skrll 	int error;
    754      1.1     skrll 	bool is_bgr = true;
    755      1.1     skrll 
    756      1.1     skrll 	if (get_bootconf_option(boot_args, "fb",
    757      1.1     skrll 			      BOOTOPT_TYPE_STRING, &ptr)) {
    758      1.1     skrll 		if (rpi_fb_parse_mode(ptr, &width, &height) == false)
    759      1.1     skrll 			return false;
    760      1.1     skrll 	}
    761      1.1     skrll 	if (width == 0 || height == 0) {
    762      1.1     skrll 		rpi_fb_get_edid_mode(&width, &height);
    763      1.1     skrll 	}
    764      1.1     skrll 	if (width == 0 || height == 0) {
    765      1.1     skrll 		width = RPI_FB_WIDTH;
    766      1.1     skrll 		height = RPI_FB_HEIGHT;
    767      1.1     skrll 	}
    768      1.1     skrll 
    769      1.1     skrll 	vb_setfb.vbt_res.width = width;
    770      1.1     skrll 	vb_setfb.vbt_res.height = height;
    771      1.1     skrll 	vb_setfb.vbt_vres.width = width;
    772      1.1     skrll 	vb_setfb.vbt_vres.height = height;
    773      1.1     skrll 	error = bcmmbox_request(BCMMBOX_CHANARM2VC, &vb_setfb,
    774      1.1     skrll 	    sizeof(vb_setfb), &res);
    775      1.1     skrll 	if (error) {
    776      1.1     skrll 		printf("%s: mbox request failed (%d)\n", __func__, error);
    777      1.1     skrll 		return false;
    778      1.1     skrll 	}
    779      1.1     skrll 
    780      1.1     skrll 	if (!vcprop_buffer_success_p(&vb_setfb.vb_hdr) ||
    781      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_res.tag) ||
    782      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_vres.tag) ||
    783      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_depth.tag) ||
    784      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_allocbuf.tag) ||
    785      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_blank.tag) ||
    786      1.1     skrll 	    !vcprop_tag_success_p(&vb_setfb.vbt_pitch.tag)) {
    787      1.1     skrll 		printf("%s: prop tag failed\n", __func__);
    788      1.1     skrll 		return false;
    789      1.1     skrll 	}
    790      1.1     skrll 
    791      1.1     skrll #ifdef VERBOSE_INIT_ARM
    792      1.1     skrll 	printf("%s: addr = 0x%x size = %d\n", __func__,
    793      1.1     skrll 	    vb_setfb.vbt_allocbuf.address,
    794      1.1     skrll 	    vb_setfb.vbt_allocbuf.size);
    795      1.1     skrll 	printf("%s: depth = %d\n", __func__, vb_setfb.vbt_depth.bpp);
    796      1.1     skrll 	printf("%s: pitch = %d\n", __func__,
    797      1.1     skrll 	    vb_setfb.vbt_pitch.linebytes);
    798      1.1     skrll 	printf("%s: width = %d height = %d\n", __func__,
    799      1.1     skrll 	    vb_setfb.vbt_res.width, vb_setfb.vbt_res.height);
    800      1.1     skrll 	printf("%s: vwidth = %d vheight = %d\n", __func__,
    801      1.1     skrll 	    vb_setfb.vbt_vres.width, vb_setfb.vbt_vres.height);
    802      1.1     skrll #endif
    803      1.1     skrll 
    804      1.1     skrll 	if (vb_setfb.vbt_allocbuf.address == 0 ||
    805      1.1     skrll 	    vb_setfb.vbt_allocbuf.size == 0 ||
    806      1.1     skrll 	    vb_setfb.vbt_res.width == 0 ||
    807      1.1     skrll 	    vb_setfb.vbt_res.height == 0 ||
    808      1.1     skrll 	    vb_setfb.vbt_vres.width == 0 ||
    809      1.1     skrll 	    vb_setfb.vbt_vres.height == 0 ||
    810      1.1     skrll 	    vb_setfb.vbt_pitch.linebytes == 0) {
    811      1.1     skrll 		printf("%s: failed to set mode %ux%u\n", __func__,
    812      1.1     skrll 		    width, height);
    813      1.1     skrll 		return false;
    814      1.1     skrll 	}
    815      1.1     skrll 
    816      1.1     skrll 	prop_dictionary_set_uint32(dict, "width", vb_setfb.vbt_res.width);
    817      1.1     skrll 	prop_dictionary_set_uint32(dict, "height", vb_setfb.vbt_res.height);
    818      1.1     skrll 	prop_dictionary_set_uint8(dict, "depth", vb_setfb.vbt_depth.bpp);
    819      1.1     skrll 	prop_dictionary_set_uint16(dict, "linebytes",
    820      1.1     skrll 	    vb_setfb.vbt_pitch.linebytes);
    821      1.1     skrll 	prop_dictionary_set_uint32(dict, "address",
    822      1.1     skrll 	    vb_setfb.vbt_allocbuf.address);
    823      1.1     skrll 
    824      1.1     skrll 	/*
    825      1.1     skrll 	 * Old firmware uses BGR. New firmware uses RGB. The get and set
    826      1.1     skrll 	 * pixel order mailbox properties don't seem to work. The firmware
    827      1.1     skrll 	 * adds a kernel cmdline option bcm2708_fb.fbswap=<0|1>, so use it
    828      1.1     skrll 	 * to determine pixel order. 0 means BGR, 1 means RGB.
    829      1.1     skrll 	 *
    830      1.1     skrll 	 * See https://github.com/raspberrypi/linux/issues/514
    831      1.1     skrll 	 */
    832      1.1     skrll 	if (get_bootconf_option(boot_args, "bcm2708_fb.fbswap",
    833      1.1     skrll 				BOOTOPT_TYPE_INT, &integer)) {
    834      1.1     skrll 		is_bgr = integer == 0;
    835      1.1     skrll 	}
    836      1.1     skrll 	prop_dictionary_set_bool(dict, "is_bgr", is_bgr);
    837      1.1     skrll 
    838      1.1     skrll 	/* if "genfb.type=<n>" is passed in cmdline, override wsdisplay type */
    839      1.1     skrll 	if (get_bootconf_option(boot_args, "genfb.type",
    840      1.1     skrll 				BOOTOPT_TYPE_INT, &integer)) {
    841      1.1     skrll 		prop_dictionary_set_uint32(dict, "wsdisplay_type", integer);
    842      1.1     skrll 	}
    843      1.1     skrll 
    844      1.1     skrll #if defined(RPI_HWCURSOR)
    845      1.1     skrll 	struct fdt_attach_args *faa = aux;
    846      1.1     skrll 	bus_space_handle_t hc;
    847      1.1     skrll 
    848      1.1     skrll 	hcursor = rpi_alloc_mem(CURSOR_ARGB_SIZE, PAGE_SIZE,
    849      1.1     skrll 	    MEM_FLAG_L1_NONALLOCATING | MEM_FLAG_HINT_PERMALOCK);
    850      1.1     skrll 	pcursor = rpi_lock_mem(hcursor);
    851      1.1     skrll #ifdef RPI_IOCTL_DEBUG
    852      1.1     skrll 	printf("hcursor: %08x\n", hcursor);
    853      1.1     skrll 	printf("pcursor: %08x\n", (uint32_t)pcursor);
    854      1.1     skrll 	printf("fb: %08x\n", (uint32_t)vb_setfb.vbt_allocbuf.address);
    855      1.1     skrll #endif
    856      1.1     skrll 	if (bus_space_map(faa->faa_bst, pcursor, CURSOR_ARGB_SIZE,
    857      1.1     skrll 	    BUS_SPACE_MAP_LINEAR|BUS_SPACE_MAP_PREFETCHABLE, &hc) != 0) {
    858      1.1     skrll 		printf("couldn't map cursor memory\n");
    859      1.1     skrll 	} else {
    860      1.1     skrll 		int i, j, k;
    861      1.1     skrll 
    862      1.1     skrll 		cmem = bus_space_vaddr(faa->faa_bst, hc);
    863      1.1     skrll 		k = 0;
    864      1.1     skrll 		for (j = 0; j < 64; j++) {
    865      1.1     skrll 			for (i = 0; i < 64; i++) {
    866      1.1     skrll 				cmem[i + k] =
    867      1.1     skrll 				 ((i & 8) ^ (j & 8)) ? 0xa0ff0000 : 0xa000ff00;
    868      1.1     skrll 			}
    869      1.1     skrll 			k += 64;
    870      1.1     skrll 		}
    871      1.1     skrll 		cpu_dcache_wb_range((vaddr_t)cmem, CURSOR_ARGB_SIZE);
    872      1.1     skrll 		rpi_fb_initcursor(pcursor, 0, 0);
    873      1.1     skrll #ifdef RPI_IOCTL_DEBUG
    874      1.1     skrll 		rpi_fb_movecursor(600, 400, 1);
    875      1.1     skrll #else
    876      1.1     skrll 		rpi_fb_movecursor(cursor_x, cursor_y, cursor_on);
    877      1.1     skrll #endif
    878      1.1     skrll 	}
    879      1.1     skrll #endif
    880      1.1     skrll 
    881      1.1     skrll 	return true;
    882      1.1     skrll }
    883      1.1     skrll 
    884      1.1     skrll 
    885      1.1     skrll #if defined(RPI_HWCURSOR)
    886      1.1     skrll static int
    887      1.1     skrll rpi_fb_do_cursor(struct wsdisplay_cursor *cur)
    888      1.1     skrll {
    889      1.1     skrll 	int pos = 0;
    890      1.1     skrll 	int shape = 0;
    891      1.1     skrll 
    892      1.1     skrll 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
    893      1.1     skrll 		if (cursor_on != cur->enable) {
    894      1.1     skrll 			cursor_on = cur->enable;
    895      1.1     skrll 			pos = 1;
    896      1.1     skrll 		}
    897      1.1     skrll 	}
    898      1.1     skrll 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
    899      1.1     skrll 
    900      1.1     skrll 		hot_x = cur->hot.x;
    901      1.1     skrll 		hot_y = cur->hot.y;
    902      1.1     skrll 		pos = 1;
    903      1.1     skrll 		shape = 1;
    904      1.1     skrll 	}
    905      1.1     skrll 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
    906      1.1     skrll 
    907      1.1     skrll 		cursor_x = cur->pos.x;
    908      1.1     skrll 		cursor_y = cur->pos.y;
    909      1.1     skrll 		pos = 1;
    910      1.1     skrll 	}
    911      1.1     skrll 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
    912      1.1     skrll 		int i;
    913      1.1     skrll 		uint32_t val;
    914      1.1     skrll 
    915      1.1     skrll 		for (i = 0; i < min(cur->cmap.count, 3); i++) {
    916      1.1     skrll 			val = (cur->cmap.red[i] << 16 ) |
    917      1.1     skrll 			      (cur->cmap.green[i] << 8) |
    918      1.1     skrll 			      (cur->cmap.blue[i] ) |
    919      1.1     skrll 			      0xff000000;
    920      1.1     skrll 			cursor_cmap[i + cur->cmap.index + 2] = val;
    921      1.1     skrll 		}
    922      1.1     skrll 		shape = 1;
    923      1.1     skrll 	}
    924      1.1     skrll 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
    925      1.1     skrll 		int err;
    926      1.1     skrll 
    927      1.1     skrll 		err = copyin(cur->mask, cursor_mask, CURSOR_BITMAP_SIZE);
    928      1.1     skrll 		err += copyin(cur->image, cursor_bitmap, CURSOR_BITMAP_SIZE);
    929      1.1     skrll 		if (err != 0)
    930      1.1     skrll 			return EFAULT;
    931      1.1     skrll 		shape = 1;
    932      1.1     skrll 	}
    933      1.1     skrll 	if (shape) {
    934      1.1     skrll 		int i, j, idx;
    935      1.1     skrll 		uint8_t mask;
    936      1.1     skrll 
    937      1.1     skrll 		for (i = 0; i < CURSOR_BITMAP_SIZE; i++) {
    938      1.1     skrll 			mask = 0x01;
    939      1.1     skrll 			for (j = 0; j < 8; j++) {
    940      1.1     skrll 				idx = ((cursor_mask[i] & mask) ? 2 : 0) |
    941      1.1     skrll 				    ((cursor_bitmap[i] & mask) ? 1 : 0);
    942      1.1     skrll 				cmem[i * 8 + j] = cursor_cmap[idx];
    943      1.1     skrll 				mask = mask << 1;
    944      1.1     skrll 			}
    945      1.1     skrll 		}
    946      1.1     skrll 		/* just in case */
    947      1.1     skrll 		cpu_dcache_wb_range((vaddr_t)cmem, CURSOR_ARGB_SIZE);
    948      1.1     skrll 		rpi_fb_initcursor(pcursor, hot_x, hot_y);
    949      1.1     skrll 	}
    950      1.1     skrll 	if (pos) {
    951      1.1     skrll 		rpi_fb_movecursor(cursor_x, cursor_y, cursor_on);
    952      1.1     skrll 	}
    953      1.1     skrll 	return 0;
    954      1.1     skrll }
    955      1.1     skrll #endif
    956      1.1     skrll 
    957      1.1     skrll static int
    958      1.1     skrll rpi_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
    959      1.1     skrll {
    960      1.1     skrll 
    961      1.1     skrll 	switch (cmd) {
    962      1.1     skrll 	case WSDISPLAYIO_SVIDEO:
    963      1.1     skrll 		{
    964      1.1     skrll 			int d = *(int *)data;
    965      1.1     skrll 			if (d == rpi_video_on)
    966      1.1     skrll 				return 0;
    967      1.1     skrll 			rpi_video_on = d;
    968      1.1     skrll 			rpi_fb_set_video(d);
    969      1.1     skrll #if defined(RPI_HWCURSOR)
    970      1.1     skrll 			rpi_fb_movecursor(cursor_x, cursor_y,
    971      1.1     skrll 			                  d ? cursor_on : 0);
    972      1.1     skrll #endif
    973      1.1     skrll 		}
    974      1.1     skrll 		return 0;
    975      1.1     skrll 	case WSDISPLAYIO_GVIDEO:
    976      1.1     skrll 		*(int *)data = rpi_video_on;
    977      1.1     skrll 		return 0;
    978      1.1     skrll #if defined(RPI_HWCURSOR)
    979      1.1     skrll 	case WSDISPLAYIO_GCURPOS:
    980      1.1     skrll 		{
    981      1.1     skrll 			struct wsdisplay_curpos *cp = (void *)data;
    982      1.1     skrll 
    983      1.1     skrll 			cp->x = cursor_x;
    984      1.1     skrll 			cp->y = cursor_y;
    985      1.1     skrll 		}
    986      1.1     skrll 		return 0;
    987      1.1     skrll 	case WSDISPLAYIO_SCURPOS:
    988      1.1     skrll 		{
    989      1.1     skrll 			struct wsdisplay_curpos *cp = (void *)data;
    990      1.1     skrll 
    991      1.1     skrll 			cursor_x = cp->x;
    992      1.1     skrll 			cursor_y = cp->y;
    993      1.1     skrll 			rpi_fb_movecursor(cursor_x, cursor_y, cursor_on);
    994      1.1     skrll 		}
    995      1.1     skrll 		return 0;
    996      1.1     skrll 	case WSDISPLAYIO_GCURMAX:
    997      1.1     skrll 		{
    998      1.1     skrll 			struct wsdisplay_curpos *cp = (void *)data;
    999      1.1     skrll 
   1000      1.1     skrll 			cp->x = 64;
   1001      1.1     skrll 			cp->y = 64;
   1002      1.1     skrll 		}
   1003      1.1     skrll 		return 0;
   1004      1.1     skrll 	case WSDISPLAYIO_SCURSOR:
   1005      1.1     skrll 		{
   1006      1.1     skrll 			struct wsdisplay_cursor *cursor = (void *)data;
   1007      1.1     skrll 
   1008      1.1     skrll 			return rpi_fb_do_cursor(cursor);
   1009      1.1     skrll 		}
   1010      1.1     skrll #endif
   1011      1.1     skrll 	default:
   1012      1.1     skrll 		return EPASSTHROUGH;
   1013      1.1     skrll 	}
   1014      1.1     skrll }
   1015      1.1     skrll 
   1016      1.1     skrll #endif
   1017      1.1     skrll 
   1018      1.1     skrll SYSCTL_SETUP(sysctl_machdep_rpi, "sysctl machdep subtree setup (rpi)")
   1019      1.1     skrll {
   1020      1.1     skrll 	sysctl_createv(clog, 0, NULL, NULL,
   1021      1.1     skrll 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
   1022      1.1     skrll 	    NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
   1023      1.1     skrll 
   1024      1.1     skrll 	sysctl_createv(clog, 0, NULL, NULL,
   1025      1.1     skrll 	    CTLFLAG_PERMANENT|CTLFLAG_READONLY,
   1026      1.1     skrll 	    CTLTYPE_INT, "firmware_revision", NULL, NULL, 0,
   1027      1.1     skrll 	    &vb.vbt_fwrev.rev, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
   1028      1.1     skrll 
   1029      1.1     skrll 	sysctl_createv(clog, 0, NULL, NULL,
   1030      1.1     skrll 	    CTLFLAG_PERMANENT|CTLFLAG_READONLY,
   1031      1.1     skrll 	    CTLTYPE_INT, "board_model", NULL, NULL, 0,
   1032      1.1     skrll 	    &vb.vbt_boardmodel.model, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
   1033      1.1     skrll 
   1034      1.1     skrll 	sysctl_createv(clog, 0, NULL, NULL,
   1035      1.1     skrll 	    CTLFLAG_PERMANENT|CTLFLAG_READONLY,
   1036      1.1     skrll 	    CTLTYPE_INT, "board_revision", NULL, NULL, 0,
   1037      1.1     skrll 	    &vb.vbt_boardrev.rev, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
   1038      1.1     skrll 
   1039      1.1     skrll 	sysctl_createv(clog, 0, NULL, NULL,
   1040      1.1     skrll 	    CTLFLAG_PERMANENT|CTLFLAG_READONLY|CTLFLAG_HEX|CTLFLAG_PRIVATE,
   1041      1.1     skrll 	    CTLTYPE_QUAD, "serial", NULL, NULL, 0,
   1042      1.1     skrll 	    &vb.vbt_serial.sn, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL);
   1043      1.1     skrll }
   1044      1.1     skrll 
   1045      1.1     skrll #if defined(SOC_BCM2835)
   1046      1.1     skrll static void
   1047      1.1     skrll bcm2835_platform_bootstrap(void)
   1048      1.1     skrll {
   1049      1.1     skrll 
   1050      1.1     skrll 	fdtbus_set_decoderegprop(false);
   1051      1.1     skrll 
   1052      1.1     skrll 	bcm2835_uartinit();
   1053      1.1     skrll 
   1054      1.1     skrll 	bcm2835_bootparams();
   1055      1.1     skrll }
   1056      1.1     skrll #endif
   1057      1.1     skrll 
   1058      1.1     skrll #if defined(SOC_BCM2836)
   1059      1.1     skrll static void
   1060      1.1     skrll bcm2836_platform_bootstrap(void)
   1061      1.1     skrll {
   1062      1.1     skrll 
   1063      1.1     skrll 	fdtbus_set_decoderegprop(false);
   1064      1.1     skrll 
   1065      1.1     skrll 	bcm2836_uartinit();
   1066      1.1     skrll 
   1067      1.1     skrll 	bcm2836_bootparams();
   1068      1.1     skrll 
   1069      1.1     skrll 	bcm2836_bootstrap();
   1070      1.1     skrll }
   1071      1.1     skrll #endif
   1072      1.1     skrll 
   1073      1.1     skrll #if defined(SOC_BCM2835)
   1074      1.1     skrll static void
   1075      1.1     skrll bcm2835_platform_init_attach_args(struct fdt_attach_args *faa)
   1076      1.1     skrll {
   1077      1.1     skrll 
   1078      1.1     skrll 	faa->faa_bst = &bcm2835_bs_tag;
   1079      1.1     skrll 	faa->faa_a4x_bst = &bcm2835_a4x_bs_tag;
   1080      1.1     skrll 	faa->faa_dmat = &bcm2835_bus_dma_tag;
   1081      1.1     skrll 
   1082      1.1     skrll 	bcm2835_bus_dma_tag._ranges = bcm2835_dma_ranges;
   1083      1.1     skrll 	bcm2835_bus_dma_tag._nranges = __arraycount(bcm2835_dma_ranges);
   1084      1.1     skrll 	bcm2835_dma_ranges[0].dr_len = bcm283x_memorysize;
   1085      1.1     skrll }
   1086      1.1     skrll #endif
   1087      1.1     skrll 
   1088      1.1     skrll #if defined(SOC_BCM2836)
   1089      1.1     skrll static void
   1090      1.1     skrll bcm2836_platform_init_attach_args(struct fdt_attach_args *faa)
   1091      1.1     skrll {
   1092      1.1     skrll 
   1093      1.1     skrll 	faa->faa_bst = &bcm2836_bs_tag;
   1094      1.1     skrll 	faa->faa_a4x_bst = &bcm2836_a4x_bs_tag;
   1095      1.1     skrll 	faa->faa_dmat = &bcm2835_bus_dma_tag;
   1096      1.1     skrll 
   1097      1.1     skrll 	bcm2835_bus_dma_tag._ranges = bcm2836_dma_ranges;
   1098      1.1     skrll 	bcm2835_bus_dma_tag._nranges = __arraycount(bcm2836_dma_ranges);
   1099      1.1     skrll 	bcm2836_dma_ranges[0].dr_len = bcm283x_memorysize;
   1100      1.1     skrll }
   1101      1.1     skrll #endif
   1102      1.1     skrll 
   1103      1.1     skrll 
   1104      1.1     skrll void
   1105      1.1     skrll bcm283x_platform_early_putchar(vaddr_t va, paddr_t pa, char c)
   1106      1.1     skrll {
   1107      1.1     skrll 	volatile uint32_t *uartaddr =
   1108      1.1     skrll 	    (armreg_sctlr_read() & CPU_CONTROL_MMU_ENABLE) ?
   1109      1.1     skrll 		(volatile uint32_t *)va :
   1110      1.1     skrll 		(volatile uint32_t *)pa;
   1111      1.1     skrll 
   1112      1.1     skrll 	while ((uartaddr[PL01XCOM_FR / 4] & PL01X_FR_TXFF) != 0)
   1113      1.1     skrll 		continue;
   1114      1.1     skrll 
   1115      1.1     skrll 	uartaddr[PL01XCOM_DR / 4] = c;
   1116      1.1     skrll 
   1117      1.1     skrll 	while ((uartaddr[PL01XCOM_FR / 4] & PL01X_FR_TXFE) == 0)
   1118      1.1     skrll 		continue;
   1119      1.1     skrll }
   1120      1.1     skrll 
   1121      1.1     skrll void
   1122      1.1     skrll bcm2835_platform_early_putchar(char c)
   1123      1.1     skrll {
   1124      1.1     skrll 	paddr_t pa = BCM2835_PERIPHERALS_BUS_TO_PHYS(BCM2835_UART0_BASE);
   1125      1.1     skrll 	vaddr_t va = BCM2835_IOPHYSTOVIRT(pa);
   1126      1.1     skrll 
   1127      1.1     skrll 	bcm283x_platform_early_putchar(va, pa, c);
   1128      1.1     skrll }
   1129      1.1     skrll 
   1130      1.1     skrll void
   1131      1.1     skrll bcm2836_platform_early_putchar(char c)
   1132      1.1     skrll {
   1133      1.1     skrll 	paddr_t pa = BCM2836_PERIPHERALS_BUS_TO_PHYS(BCM2835_UART0_BASE);
   1134      1.1     skrll 	vaddr_t va = BCM2835_IOPHYSTOVIRT(pa);
   1135      1.1     skrll 
   1136      1.1     skrll 	bcm283x_platform_early_putchar(va, pa, c);
   1137      1.1     skrll }
   1138      1.1     skrll 
   1139      1.1     skrll #define	BCM283x_REF_FREQ	19200000
   1140      1.1     skrll 
   1141      1.1     skrll void
   1142      1.1     skrll bcm2837_platform_early_putchar(char c)
   1143      1.1     skrll {
   1144      1.1     skrll #define AUCONSADDR_PA	BCM2836_PERIPHERALS_BUS_TO_PHYS(BCM2835_AUX_UART_BASE)
   1145      1.1     skrll #define AUCONSADDR_VA	BCM2835_IOPHYSTOVIRT(AUCONSADDR_PA)
   1146      1.1     skrll 	volatile uint32_t *uartaddr =
   1147      1.1     skrll 	    (armreg_sctlr_read() & CPU_CONTROL_MMU_ENABLE) ?
   1148      1.1     skrll 		(volatile uint32_t *)AUCONSADDR_VA :
   1149      1.1     skrll 		(volatile uint32_t *)AUCONSADDR_PA;
   1150      1.1     skrll 
   1151      1.1     skrll 	while ((uartaddr[com_lsr] & LSR_TXRDY) == 0)
   1152      1.1     skrll 		;
   1153      1.1     skrll 
   1154      1.1     skrll 	uartaddr[com_data] = c;
   1155      1.1     skrll }
   1156      1.1     skrll 
   1157      1.1     skrll static void
   1158      1.1     skrll bcm283x_platform_device_register(device_t dev, void *aux)
   1159      1.1     skrll {
   1160      1.1     skrll 	prop_dictionary_t dict = device_properties(dev);
   1161      1.1     skrll 
   1162      1.1     skrll 	if (device_is_a(dev, "bcmdmac") &&
   1163      1.1     skrll 	    vcprop_tag_success_p(&vb.vbt_dmachan.tag)) {
   1164      1.1     skrll 		prop_dictionary_set_uint32(dict,
   1165      1.1     skrll 		    "chanmask", vb.vbt_dmachan.mask);
   1166      1.1     skrll 	}
   1167      1.1     skrll #if NSDHC > 0
   1168      1.1     skrll 	if (booted_device == NULL &&
   1169      1.1     skrll 	    device_is_a(dev, "ld") &&
   1170      1.1     skrll 	    device_is_a(device_parent(dev), "sdmmc")) {
   1171      1.1     skrll 		booted_partition = 0;
   1172      1.1     skrll 		booted_device = dev;
   1173      1.1     skrll 	}
   1174      1.1     skrll #endif
   1175      1.1     skrll 	if (device_is_a(dev, "usmsc") &&
   1176      1.1     skrll 	    vcprop_tag_success_p(&vb.vbt_macaddr.tag)) {
   1177      1.1     skrll 		const uint8_t enaddr[ETHER_ADDR_LEN] = {
   1178      1.1     skrll 		     (vb.vbt_macaddr.addr >> 0) & 0xff,
   1179      1.1     skrll 		     (vb.vbt_macaddr.addr >> 8) & 0xff,
   1180      1.1     skrll 		     (vb.vbt_macaddr.addr >> 16) & 0xff,
   1181      1.1     skrll 		     (vb.vbt_macaddr.addr >> 24) & 0xff,
   1182      1.1     skrll 		     (vb.vbt_macaddr.addr >> 32) & 0xff,
   1183      1.1     skrll 		     (vb.vbt_macaddr.addr >> 40) & 0xff
   1184      1.1     skrll 		};
   1185      1.1     skrll 
   1186      1.1     skrll 		prop_data_t pd = prop_data_create_data(enaddr, ETHER_ADDR_LEN);
   1187      1.1     skrll 		KASSERT(pd != NULL);
   1188      1.1     skrll 		if (prop_dictionary_set(device_properties(dev), "mac-address",
   1189      1.1     skrll 		    pd) == false) {
   1190      1.1     skrll 			aprint_error_dev(dev,
   1191      1.1     skrll 			    "WARNING: Unable to set mac-address property\n");
   1192      1.1     skrll 		}
   1193      1.1     skrll 		prop_object_release(pd);
   1194      1.1     skrll 	}
   1195      1.1     skrll 
   1196      1.1     skrll #if NGENFB > 0
   1197      1.1     skrll 	if (device_is_a(dev, "genfb")) {
   1198      1.1     skrll 		char *ptr;
   1199      1.1     skrll 
   1200      1.1     skrll 		bcmgenfb_set_console_dev(dev);
   1201      1.1     skrll 		bcmgenfb_set_ioctl(&rpi_ioctl);
   1202      1.1     skrll #ifdef DDB
   1203      1.1     skrll 		db_trap_callback = bcmgenfb_ddb_trap_callback;
   1204      1.1     skrll #endif
   1205      1.1     skrll 		if (rpi_fb_init(dict, aux) == false)
   1206      1.1     skrll 			return;
   1207      1.1     skrll 		if (get_bootconf_option(boot_args, "console",
   1208      1.1     skrll 		    BOOTOPT_TYPE_STRING, &ptr) && strncmp(ptr, "fb", 2) == 0) {
   1209      1.1     skrll 			prop_dictionary_set_bool(dict, "is_console", true);
   1210      1.1     skrll #if NUKBD > 0
   1211      1.1     skrll 			/* allow ukbd to be the console keyboard */
   1212      1.1     skrll 			ukbd_cnattach();
   1213      1.1     skrll #endif
   1214      1.1     skrll 		} else {
   1215      1.1     skrll 			prop_dictionary_set_bool(dict, "is_console", false);
   1216      1.1     skrll 		}
   1217      1.1     skrll 	}
   1218      1.1     skrll #endif
   1219      1.1     skrll }
   1220      1.1     skrll 
   1221      1.1     skrll static u_int
   1222      1.1     skrll bcm283x_platform_uart_freq(void)
   1223      1.1     skrll {
   1224      1.1     skrll 
   1225      1.1     skrll 	return uart_clk;
   1226      1.1     skrll }
   1227      1.1     skrll 
   1228      1.1     skrll #if defined(SOC_BCM2835)
   1229      1.1     skrll static const struct arm_platform bcm2835_platform = {
   1230      1.1     skrll 	.devmap = bcm2835_platform_devmap,
   1231      1.1     skrll 	.bootstrap = bcm2835_platform_bootstrap,
   1232      1.1     skrll 	.init_attach_args = bcm2835_platform_init_attach_args,
   1233      1.1     skrll 	.early_putchar = bcm2835_platform_early_putchar,
   1234      1.1     skrll 	.device_register = bcm283x_platform_device_register,
   1235      1.1     skrll 	.reset = bcm2835_system_reset,
   1236      1.1     skrll 	.delay = bcm2835_tmr_delay,
   1237      1.1     skrll 	.uart_freq = bcm283x_platform_uart_freq,
   1238      1.1     skrll };
   1239      1.1     skrll 
   1240      1.1     skrll ARM_PLATFORM(bcm2835, "brcm,bcm2835", &bcm2835_platform);
   1241      1.1     skrll #endif
   1242      1.1     skrll 
   1243      1.1     skrll #if defined(SOC_BCM2836)
   1244      1.1     skrll static u_int
   1245      1.1     skrll bcm2837_platform_uart_freq(void)
   1246      1.1     skrll {
   1247      1.1     skrll 
   1248      1.1     skrll 	return core_clk * 2;
   1249      1.1     skrll }
   1250      1.1     skrll 
   1251      1.1     skrll static const struct arm_platform bcm2836_platform = {
   1252      1.1     skrll 	.devmap = bcm2836_platform_devmap,
   1253      1.1     skrll 	.bootstrap = bcm2836_platform_bootstrap,
   1254      1.1     skrll 	.init_attach_args = bcm2836_platform_init_attach_args,
   1255      1.1     skrll 	.early_putchar = bcm2836_platform_early_putchar,
   1256      1.1     skrll 	.device_register = bcm283x_platform_device_register,
   1257      1.1     skrll 	.reset = bcm2835_system_reset,
   1258      1.1     skrll 	.delay = gtmr_delay,
   1259      1.1     skrll 	.uart_freq = bcm283x_platform_uart_freq,
   1260      1.1     skrll };
   1261      1.1     skrll 
   1262      1.1     skrll static const struct arm_platform bcm2837_platform = {
   1263      1.1     skrll 	.devmap = bcm2836_platform_devmap,
   1264      1.1     skrll 	.bootstrap = bcm2836_platform_bootstrap,
   1265      1.1     skrll 	.init_attach_args = bcm2836_platform_init_attach_args,
   1266      1.1     skrll 	.early_putchar = bcm2837_platform_early_putchar,
   1267      1.1     skrll 	.device_register = bcm283x_platform_device_register,
   1268      1.1     skrll 	.reset = bcm2835_system_reset,
   1269      1.1     skrll 	.delay = gtmr_delay,
   1270      1.1     skrll 	.uart_freq = bcm2837_platform_uart_freq,
   1271      1.1     skrll };
   1272      1.1     skrll 
   1273      1.1     skrll ARM_PLATFORM(bcm2836, "brcm,bcm2836", &bcm2836_platform);
   1274      1.1     skrll ARM_PLATFORM(bcm2837, "brcm,bcm2837", &bcm2837_platform);
   1275      1.1     skrll #endif
   1276