1/*	$NetBSD: amiga_init.c,v 1.8 2009/07/21 09:49:15 phx Exp $	*/
2
3/*
4 * Copyright (c) 1994 Michael L. Hitch
5 * Copyright (c) 1993 Markus Wild
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *      This product includes software developed by Markus Wild.
19 * 4. The name of the author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: amiga_init.c,v 1.8 2009/07/21 09:49:15 phx Exp $");
36
37#include <sys/param.h>
38#include <amiga/amiga/cc.h>
39#include <amiga/amiga/cia.h>
40#include <amiga/amiga/custom.h>
41#include <amiga/amiga/cfdev.h>
42#include <amiga/amiga/memlist.h>
43
44int machineid;
45
46vaddr_t CHIPMEMADDR;
47vaddr_t chipmem_start;
48vaddr_t chipmem_end;
49
50u_long boot_fphystart, boot_fphysize, cphysize;
51u_long boot_flags;
52
53char *esym;			/* start address of cfdev/memlist-area */
54
55struct boot_memlist *memlist;
56
57struct cfdev *cfdev;
58int ncfdev;
59
60u_long scsi_nosync;
61int shift_nosync;
62
63void set_boot_args(int, u_long, u_long, u_long, char *, int, u_long, u_long);
64
65
66/*
67 * called from locore.S, before initppc()
68 */
69void
70set_boot_args(int boot_howto, u_long fstart, u_long fsize, u_long csize,
71              char *esymaddr, int cpuid, u_long flags, u_long inhsync)
72{
73	char *end_loaded;
74
75	boothowto = boot_howto;
76	boot_fphystart = fstart;
77	boot_fphysize = fsize;
78	cphysize = csize;
79	esym = end_loaded = esymaddr;
80	machineid = cpuid;
81	boot_flags = flags;
82	scsi_nosync = inhsync;
83
84	/*
85	 * The kernel ends at end_loaded, plus the cfdev and memlist
86	 * structures we placed there in the loader.
87	 * esym already takes a potential symbol-table into account.
88	 */
89	ncfdev = *(int *)end_loaded;
90	cfdev = (struct cfdev *)(end_loaded + sizeof(int));
91	end_loaded += sizeof(int) + ncfdev * sizeof(struct cfdev);
92	memlist = (struct boot_memlist *)end_loaded;
93
94	CHIPMEMADDR = 0x0;
95	chipmem_start = CHIPMEMADDR;
96	chipmem_end  = (vaddr_t)csize;
97
98	CIAADDR = 0xbfd000;
99	CIAAbase = CIAADDR + 0x1001;
100	CIABbase = CIAADDR;
101
102	CUSTOMADDR = 0xdff000;
103	CUSTOMbase = CUSTOMADDR;
104}
105
106/*
107 * called by cc_init_chipmem() from amiga/amiga/cc.c
108 */
109void *
110chipmem_steal(long amount)
111{
112
113	/* steal from top of chipmem, as amiga68k does */
114	vaddr_t p = chipmem_end - amount;
115	if (p & 1)
116		p = p - 1;
117	chipmem_end = p;
118	if(chipmem_start > chipmem_end)
119		panic("not enough chip memory");
120	return((void *)p);
121}
122
123/*
124 * Used by certain drivers currently to allocate zorro II or chip mem
125 * for bounce buffers. For amigappc we will only return chip memory.
126 */
127void *
128alloc_z2mem(long amount)
129{
130
131	return (alloc_chipmem(amount));
132}
133