xref: /openbmc/linux/arch/arm/mach-rpc/include/mach/uncompress.h (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2a09e64fbSRussell King /*
3a09e64fbSRussell King  *  arch/arm/mach-rpc/include/mach/uncompress.h
4a09e64fbSRussell King  *
5a09e64fbSRussell King  *  Copyright (C) 1996 Russell King
6a09e64fbSRussell King  */
7a09e64fbSRussell King #define VIDMEM ((char *)SCREEN_START)
8a09e64fbSRussell King 
9fced80c7SRussell King #include <linux/io.h>
10a09e64fbSRussell King #include <mach/hardware.h>
11a09e64fbSRussell King #include <asm/setup.h>
12a09e64fbSRussell King #include <asm/page.h>
13a09e64fbSRussell King 
14a09e64fbSRussell King int video_size_row;
15a09e64fbSRussell King unsigned char bytes_per_char_h;
16a09e64fbSRussell King extern unsigned long con_charconvtable[256];
17a09e64fbSRussell King 
18a09e64fbSRussell King struct param_struct {
19a09e64fbSRussell King 	unsigned long page_size;
20a09e64fbSRussell King 	unsigned long nr_pages;
21a09e64fbSRussell King 	unsigned long ramdisk_size;
22a09e64fbSRussell King 	unsigned long mountrootrdonly;
23a09e64fbSRussell King 	unsigned long rootdev;
24a09e64fbSRussell King 	unsigned long video_num_cols;
25a09e64fbSRussell King 	unsigned long video_num_rows;
26a09e64fbSRussell King 	unsigned long video_x;
27a09e64fbSRussell King 	unsigned long video_y;
28a09e64fbSRussell King 	unsigned long memc_control_reg;
29a09e64fbSRussell King 	unsigned char sounddefault;
30a09e64fbSRussell King 	unsigned char adfsdrives;
31a09e64fbSRussell King 	unsigned char bytes_per_char_h;
32a09e64fbSRussell King 	unsigned char bytes_per_char_v;
33a09e64fbSRussell King 	unsigned long unused[256/4-11];
34a09e64fbSRussell King };
35a09e64fbSRussell King 
36a09e64fbSRussell King static const unsigned long palette_4[16] = {
37a09e64fbSRussell King 	0x00000000,
38a09e64fbSRussell King 	0x000000cc,
39a09e64fbSRussell King 	0x0000cc00,             /* Green   */
40a09e64fbSRussell King 	0x0000cccc,             /* Yellow  */
41a09e64fbSRussell King 	0x00cc0000,             /* Blue    */
42a09e64fbSRussell King 	0x00cc00cc,             /* Magenta */
43a09e64fbSRussell King 	0x00cccc00,             /* Cyan    */
44a09e64fbSRussell King 	0x00cccccc,             /* White   */
45a09e64fbSRussell King 	0x00000000,
46a09e64fbSRussell King 	0x000000ff,
47a09e64fbSRussell King 	0x0000ff00,
48a09e64fbSRussell King 	0x0000ffff,
49a09e64fbSRussell King 	0x00ff0000,
50a09e64fbSRussell King 	0x00ff00ff,
51a09e64fbSRussell King 	0x00ffff00,
52a09e64fbSRussell King 	0x00ffffff
53a09e64fbSRussell King };
54a09e64fbSRussell King 
55a09e64fbSRussell King #define palette_setpixel(p)	*(unsigned long *)(IO_START+0x00400000) = 0x10000000|((p) & 255)
56a09e64fbSRussell King #define palette_write(v)	*(unsigned long *)(IO_START+0x00400000) = 0x00000000|((v) & 0x00ffffff)
57a09e64fbSRussell King 
58a09e64fbSRussell King /*
59a09e64fbSRussell King  * params_phys is a linker defined symbol - see
60a09e64fbSRussell King  * arch/arm/boot/compressed/Makefile
61a09e64fbSRussell King  */
62a09e64fbSRussell King extern __attribute__((pure)) struct param_struct *params(void);
63a09e64fbSRussell King #define params (params())
64a09e64fbSRussell King 
65a09e64fbSRussell King #ifndef STANDALONE_DEBUG
668ea0de4bSNicolas Pitre unsigned long video_num_cols;
678ea0de4bSNicolas Pitre unsigned long video_num_rows;
688ea0de4bSNicolas Pitre unsigned long video_x;
698ea0de4bSNicolas Pitre unsigned long video_y;
708ea0de4bSNicolas Pitre unsigned char bytes_per_char_v;
718ea0de4bSNicolas Pitre int white;
72a09e64fbSRussell King 
73a09e64fbSRussell King /*
74a09e64fbSRussell King  * This does not append a newline
75a09e64fbSRussell King  */
putc(int c)764d2b7d4cSArnd Bergmann static inline void putc(int c)
77a09e64fbSRussell King {
78a09e64fbSRussell King 	extern void ll_write_char(char *, char c, char white);
79a09e64fbSRussell King 	int x,y;
80a09e64fbSRussell King 	char *ptr;
81a09e64fbSRussell King 
82a09e64fbSRussell King 	x = video_x;
83a09e64fbSRussell King 	y = video_y;
84a09e64fbSRussell King 
85a09e64fbSRussell King 	if (c == '\n') {
86a09e64fbSRussell King 		if (++y >= video_num_rows)
87a09e64fbSRussell King 			y--;
88a09e64fbSRussell King 	} else if (c == '\r') {
89a09e64fbSRussell King 		x = 0;
90a09e64fbSRussell King 	} else {
91a09e64fbSRussell King 		ptr = VIDMEM + ((y*video_num_cols*bytes_per_char_v+x)*bytes_per_char_h);
92a09e64fbSRussell King 		ll_write_char(ptr, c, white);
93a09e64fbSRussell King 		if (++x >= video_num_cols) {
94a09e64fbSRussell King 			x = 0;
95a09e64fbSRussell King 			if ( ++y >= video_num_rows ) {
96a09e64fbSRussell King 				y--;
97a09e64fbSRussell King 			}
98a09e64fbSRussell King 		}
99a09e64fbSRussell King 	}
100a09e64fbSRussell King 
101a09e64fbSRussell King 	video_x = x;
102a09e64fbSRussell King 	video_y = y;
103a09e64fbSRussell King }
104a09e64fbSRussell King 
flush(void)105a09e64fbSRussell King static inline void flush(void)
106a09e64fbSRussell King {
107a09e64fbSRussell King }
108a09e64fbSRussell King 
109a09e64fbSRussell King /*
110a09e64fbSRussell King  * Setup for decompression
111a09e64fbSRussell King  */
arch_decomp_setup(void)112a09e64fbSRussell King static void arch_decomp_setup(void)
113a09e64fbSRussell King {
114a09e64fbSRussell King 	int i;
115a09e64fbSRussell King 	struct tag *t = (struct tag *)params;
116a09e64fbSRussell King 	unsigned int nr_pages = 0, page_size = PAGE_SIZE;
117a09e64fbSRussell King 
118e579201aSRussell King 	if (t->hdr.tag == ATAG_CORE) {
119e579201aSRussell King 		for (; t->hdr.size; t = tag_next(t)) {
120e579201aSRussell King 			if (t->hdr.tag == ATAG_VIDEOTEXT) {
121a09e64fbSRussell King 				video_num_rows = t->u.videotext.video_lines;
122a09e64fbSRussell King 				video_num_cols = t->u.videotext.video_cols;
123a09e64fbSRussell King 				video_x = t->u.videotext.x;
124a09e64fbSRussell King 				video_y = t->u.videotext.y;
125e579201aSRussell King 			} else if (t->hdr.tag == ATAG_VIDEOLFB) {
126e579201aSRussell King 				bytes_per_char_h = t->u.videolfb.lfb_depth;
127e579201aSRussell King 				bytes_per_char_v = 8;
128e579201aSRussell King 			} else if (t->hdr.tag == ATAG_MEM) {
129a09e64fbSRussell King 				page_size = PAGE_SIZE;
130a09e64fbSRussell King 				nr_pages += (t->u.mem.size / PAGE_SIZE);
131a09e64fbSRussell King 			}
132a09e64fbSRussell King 		}
133e579201aSRussell King 	} else {
134a09e64fbSRussell King 		nr_pages = params->nr_pages;
135a09e64fbSRussell King 		page_size = params->page_size;
136a09e64fbSRussell King 		video_num_rows = params->video_num_rows;
137a09e64fbSRussell King 		video_num_cols = params->video_num_cols;
138a09e64fbSRussell King 		video_x = params->video_x;
139a09e64fbSRussell King 		video_y = params->video_y;
140a09e64fbSRussell King 		bytes_per_char_h = params->bytes_per_char_h;
141a09e64fbSRussell King 		bytes_per_char_v = params->bytes_per_char_v;
142a09e64fbSRussell King 	}
143a09e64fbSRussell King 
144a09e64fbSRussell King 	video_size_row = video_num_cols * bytes_per_char_h;
145a09e64fbSRussell King 
146a09e64fbSRussell King 	if (bytes_per_char_h == 4)
147a09e64fbSRussell King 		for (i = 0; i < 256; i++)
148a09e64fbSRussell King 			con_charconvtable[i] =
149a09e64fbSRussell King 				(i & 128 ? 1 << 0  : 0) |
150a09e64fbSRussell King 				(i & 64  ? 1 << 4  : 0) |
151a09e64fbSRussell King 				(i & 32  ? 1 << 8  : 0) |
152a09e64fbSRussell King 				(i & 16  ? 1 << 12 : 0) |
153a09e64fbSRussell King 				(i & 8   ? 1 << 16 : 0) |
154a09e64fbSRussell King 				(i & 4   ? 1 << 20 : 0) |
155a09e64fbSRussell King 				(i & 2   ? 1 << 24 : 0) |
156a09e64fbSRussell King 				(i & 1   ? 1 << 28 : 0);
157a09e64fbSRussell King 	else
158a09e64fbSRussell King 		for (i = 0; i < 16; i++)
159a09e64fbSRussell King 			con_charconvtable[i] =
160a09e64fbSRussell King 				(i & 8   ? 1 << 0  : 0) |
161a09e64fbSRussell King 				(i & 4   ? 1 << 8  : 0) |
162a09e64fbSRussell King 				(i & 2   ? 1 << 16 : 0) |
163a09e64fbSRussell King 				(i & 1   ? 1 << 24 : 0);
164a09e64fbSRussell King 
165a09e64fbSRussell King 
166a09e64fbSRussell King 	palette_setpixel(0);
167a09e64fbSRussell King 	if (bytes_per_char_h == 1) {
168a09e64fbSRussell King 		palette_write (0);
169a09e64fbSRussell King 		palette_write (0x00ffffff);
170a09e64fbSRussell King 		for (i = 2; i < 256; i++)
171a09e64fbSRussell King 			palette_write (0);
172a09e64fbSRussell King 		white = 1;
173a09e64fbSRussell King 	} else {
174a09e64fbSRussell King 		for (i = 0; i < 256; i++)
175a09e64fbSRussell King 			palette_write (i < 16 ? palette_4[i] : 0);
176a09e64fbSRussell King 		white = 7;
177a09e64fbSRussell King 	}
178a09e64fbSRussell King 
179a09e64fbSRussell King 	if (nr_pages * page_size < 4096*1024) error("<4M of mem\n");
180a09e64fbSRussell King }
181a09e64fbSRussell King #endif
182