Skip to content

Commit d65aba8

Browse files
committed
Update FramebufferInfo
1 parent 22f5cf9 commit d65aba8

File tree

8 files changed

+131
-89
lines changed

8 files changed

+131
-89
lines changed

kernel/src/arch/aarch64/board/raspi3/mailbox.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! (ref: https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface)
44
5-
use super::fb::FramebufferInfo;
65
use crate::memory::virt_to_phys;
76
use aarch64::asm;
87
use alloc::string::String;
@@ -175,6 +174,35 @@ struct PropertyMailboxRequest<T: Sized> {
175174
#[derive(Debug)]
176175
struct Align16<T: Sized>(PropertyMailboxRequest<T>);
177176

177+
/// Some information of raspberry pi framebuffer
178+
#[repr(C)]
179+
#[derive(Debug, Clone, Copy)]
180+
pub struct RaspiFramebufferInfo {
181+
/// visible width
182+
pub xres: u32,
183+
/// visible height
184+
pub yres: u32,
185+
/// virtual width
186+
pub xres_virtual: u32,
187+
/// virtual height
188+
pub yres_virtual: u32,
189+
/// virtual offset x
190+
pub xoffset: u32,
191+
/// virtual offset y
192+
pub yoffset: u32,
193+
194+
/// bits per pixel
195+
pub depth: u32,
196+
/// bytes per line
197+
pub pitch: u32,
198+
199+
/// bus address, starts from 0xC0000000/0x40000000
200+
/// (see https://github.com/raspberrypi/firmware/wiki/Accessing-mailboxes)
201+
pub bus_addr: u32,
202+
/// screen buffer size
203+
pub screen_size: u32,
204+
}
205+
178206
/// Pack a sequence of concatenated tags into a request, and send the address
179207
/// to the mailbox.
180208
/// Returns `PropertyMailboxResult<typeof($tags)>`.
@@ -285,12 +313,12 @@ pub fn framebuffer_set_virtual_offset(
285313
}
286314

287315
/// Allocate framebuffer on GPU and try to set width/height/depth.
288-
/// Returns `FramebufferInfo`.
316+
/// Returns `RaspiFramebufferInfo`.
289317
pub fn framebuffer_alloc(
290318
width: u32,
291319
height: u32,
292320
depth: u32,
293-
) -> PropertyMailboxResult<FramebufferInfo> {
321+
) -> PropertyMailboxResult<RaspiFramebufferInfo> {
294322
#[repr(C, packed)]
295323
#[derive(Debug)]
296324
struct FramebufferAllocTag {
@@ -348,7 +376,7 @@ pub fn framebuffer_alloc(
348376
};
349377

350378
let ret = send_request!(tags)?;
351-
Ok(FramebufferInfo {
379+
Ok(RaspiFramebufferInfo {
352380
xres: ret.set_physical_size.buf[0],
353381
yres: ret.set_physical_size.buf[1],
354382
xres_virtual: ret.set_virtual_size.buf[0],

kernel/src/arch/aarch64/board/raspi3/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod mailbox;
1010
pub mod serial;
1111
pub mod timer;
1212

13-
use fb::{ColorConfig, FramebufferResult};
13+
use fb::{ColorDepth, ColorFormat, FramebufferInfo, FramebufferResult};
1414

1515
/// Initialize serial port before other initializations.
1616
pub fn init_serial_early() {
@@ -75,10 +75,23 @@ pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult {
7575
))?;
7676
}
7777

78-
let color_config = match info.depth {
79-
16 => ColorConfig::RGB565,
80-
32 => ColorConfig::BGRA8888,
78+
let depth = ColorDepth::try_from(info.depth)?;
79+
let format = match info.depth {
80+
16 => ColorFormat::RGB565,
81+
32 => ColorFormat::BGRA8888,
8182
_ => Err(format!("unsupported color depth {}", info.depth))?,
8283
};
83-
Ok((info, color_config, vaddr))
84+
Ok(FramebufferInfo {
85+
xres: info.xres,
86+
yres: info.yres,
87+
xres_virtual: info.xres_virtual,
88+
yres_virtual: info.yres_virtual,
89+
xoffset: info.xoffset,
90+
yoffset: info.yoffset,
91+
depth: depth,
92+
format: format,
93+
paddr: paddr as usize,
94+
vaddr: vaddr,
95+
screen_size: info.screen_size as usize,
96+
})
8497
}

kernel/src/arch/mipsel/board/malta/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ pub fn init_driver() {
3737
}
3838

3939
pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> fb::FramebufferResult {
40-
let fb_info = FramebufferInfo {
40+
Ok(FramebufferInfo {
4141
xres: 800,
4242
yres: 600,
4343
xres_virtual: 800,
4444
yres_virtual: 600,
4545
xoffset: 0,
4646
yoffset: 0,
47-
depth: 8,
48-
pitch: 800,
49-
bus_addr: 0xb0000000,
47+
depth: fb::ColorDepth::try_from(8)?,
48+
format: fb::ColorFormat::VgaPalette,
49+
paddr: 0xb0000000,
50+
vaddr: 0xb0000000,
5051
screen_size: 800 * 600,
51-
};
52-
Ok((fb_info, fb::ColorConfig::VgaPalette, 0xb0000000))
52+
})
5353
}

kernel/src/arch/mipsel/board/thinpad/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ pub fn init_driver() {
2828
}
2929

3030
pub fn probe_fb_info(width: u32, height: u32, depth: u32) -> FramebufferResult {
31-
let fb_info = FramebufferInfo {
31+
Ok(FramebufferInfo {
3232
xres: 800,
3333
yres: 600,
3434
xres_virtual: 800,
3535
yres_virtual: 600,
3636
xoffset: 0,
3737
yoffset: 0,
38-
depth: 8,
39-
pitch: 800,
40-
bus_addr: 0xa2000000,
38+
depth: fb::ColorDepth::try_from(8)?,
39+
format: fb::ColorFormat::RGB332,
40+
paddr: 0xa2000000,
41+
vaddr: 0xa2000000,
4142
screen_size: 800 * 600,
42-
};
43-
Ok((fb_info, fb::ColorConfig::RGB332, 0xa2000000))
43+
})
4444
}

kernel/src/arch/x86_64/board/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::consts::KERNEL_OFFSET;
55
use crate::memory::phys_to_virt;
66
use bootloader::bootinfo::{BootInfo, VbeModeInfo};
77
use core::mem::zeroed;
8-
use fb::{ColorConfig, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
8+
use fb::{ColorFormat, ColorDepth, FramebufferInfo, FramebufferResult, FRAME_BUFFER};
99

1010
static mut VBE_MODE: VbeModeInfo = VbeModeInfo {
1111
attributes: 0,
@@ -54,25 +54,25 @@ pub fn probe_fb_info(_width: u32, _height: u32, _depth: u32) -> FramebufferResul
5454
let pitch = unsafe { VBE_MODE.pitch as u32 };
5555
let framebuffer = unsafe { VBE_MODE.framebuffer as usize };
5656
let depth = unsafe { VBE_MODE.bpp as u32 };
57-
let fb_info = FramebufferInfo {
57+
let format = if depth == 8 {
58+
fb::ColorFormat::RGB332
59+
} else if depth == 16 {
60+
fb::ColorFormat::RGB565
61+
} else {
62+
// assume BGRA8888 for now
63+
fb::ColorFormat::RGBA8888
64+
};
65+
Ok(FramebufferInfo {
5866
xres: width,
5967
yres: height,
6068
xres_virtual: width,
6169
yres_virtual: height,
6270
xoffset: 0,
6371
yoffset: 0,
64-
depth: depth,
65-
pitch: pitch, // TOKNOW
66-
bus_addr: framebuffer as u32,
67-
screen_size: width * height * (depth / 8),
68-
};
69-
let config = if depth == 8 {
70-
fb::ColorConfig::RGB332
71-
} else if depth == 16 {
72-
fb::ColorConfig::RGB565
73-
} else {
74-
// assume BGRA8888 for now
75-
fb::ColorConfig::RGBA8888
76-
};
77-
Ok((fb_info, config, phys_to_virt(framebuffer)))
72+
depth: ColorDepth::try_from(depth)?,
73+
format: format,
74+
paddr: framebuffer,
75+
vaddr: phys_to_virt(framebuffer),
76+
screen_size: (width * height * (depth / 8)) as usize,
77+
})
7878
}

0 commit comments

Comments
 (0)