luwen_api/chip/
creation.rs1use std::sync::Arc;
5
6use luwen_def::Arch;
7
8use crate::{
9 error::{BtWrapper, PlatformError},
10 CallbackStorage,
11};
12
13use super::{
14 communication::chip_comms::load_axi_table, ArcIf, Blackhole, Chip, ChipComms, ChipInterface,
15 Wormhole,
16};
17
18impl Chip {
19 pub fn wh_open<T: Clone + Send + Sync + 'static>(
20 arch: Arch,
21 backend: CallbackStorage<T>,
22 ) -> Result<Wormhole, PlatformError> {
23 if let Arch::Wormhole = arch {
24 let version = [0u8; 4];
25 let version = u32::from_le_bytes(version);
26
27 let arc_if = ArcIf {
28 axi_data: load_axi_table("wormhole-axi-pci.bin", version),
29 };
30
31 Ok(Wormhole::init(
32 false,
33 true,
34 arc_if,
35 Arc::new(backend) as Arc<dyn ChipInterface + Sync + Send>,
36 )?)
37 } else {
38 Err(PlatformError::WrongChipArch {
39 actual: arch,
40 expected: Arch::Wormhole,
41 backtrace: BtWrapper::capture(),
42 })
43 }
44 }
45
46 pub fn bh_open<T: Clone + Send + Sync + 'static>(
47 arch: Arch,
48 backend: CallbackStorage<T>,
49 ) -> Result<Blackhole, PlatformError> {
50 if let Arch::Blackhole = arch {
51 let version = [0u8; 4];
52 let version = u32::from_le_bytes(version);
53
54 let arc_if = super::communication::chip_comms::NocIf {
55 axi_data: load_axi_table("blackhole-axi-pci.bin", version),
56 noc_id: 0,
57 x: 8,
58 y: 0,
59 };
60
61 Ok(Blackhole::init(
62 Arc::new(arc_if) as Arc<dyn ChipComms + Sync + Send>,
63 Arc::new(super::communication::chip_interface::NocInterface {
64 noc_id: 0,
65 x: 8,
66 y: 0,
67 backing: Box::new(backend),
68 }) as Arc<dyn ChipInterface + Sync + Send>,
69 )?)
70 } else {
71 Err(PlatformError::WrongChipArch {
72 actual: arch,
73 expected: Arch::Blackhole,
74 backtrace: BtWrapper::capture(),
75 })
76 }
77 }
78
79 pub fn open<T: Clone + Send + Sync + 'static>(
80 arch: Arch,
81 backend: CallbackStorage<T>,
82 ) -> Result<Chip, PlatformError> {
83 Ok(Chip {
84 inner: match arch {
85 #[allow(deprecated)]
86 Arch::Grayskull => unimplemented!("grayskull support has been sunset"),
87 Arch::Wormhole => Box::new(Self::wh_open(arch, backend)?),
88 Arch::Blackhole => Box::new(Self::bh_open(arch, backend)?),
89 },
90 })
91 }
92}