Skip to content

Commit

Permalink
#0: Fix ncrisc code overflow problem
Browse files Browse the repository at this point in the history
NCRISC has 2 limits: code cannot exceed the FIRMWARE_SIZE and code+data size
cannot exceed the INIT_IRAM_L1_SIZE.  On BH, this is spoofed.  When the ring
buffer comes this will get simplified somewhat as then the 2nd check will
be just a "max size" check against the ring buffer
  • Loading branch information
pgkeller committed Oct 3, 2024
1 parent b079f8c commit 32c62b9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
13 changes: 8 additions & 5 deletions tt_metal/hw/inc/blackhole/dev_mem_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
/////////////
// Firmware/kernel code holes
#define MEM_BOOT_CODE_SIZE 4
#define MEM_BRISC_FIRMWARE_SIZE (10 * 1024)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024)
#define MEM_TRISC0_FIRMWARE_SIZE (16 * 1024)
#define MEM_TRISC1_FIRMWARE_SIZE (16 * 1024)
#define MEM_TRISC2_FIRMWARE_SIZE (16 * 1024)
#define MEM_BRISC_FIRMWARE_SIZE (10 * 1024 + MEM_BRISC_LOCAL_SIZE)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024 + MEM_NCRISC_LOCAL_SIZE)
#define MEM_TRISC0_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC1_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC2_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_ZEROS_SIZE 512

#define MEM_BOOT_CODE_BASE 0
Expand All @@ -61,6 +61,9 @@
#define MEM_TRISC1_FIRMWARE_BASE (MEM_TRISC0_FIRMWARE_BASE + MEM_TRISC0_FIRMWARE_SIZE)
#define MEM_TRISC2_FIRMWARE_BASE (MEM_TRISC1_FIRMWARE_BASE + MEM_TRISC1_FIRMWARE_SIZE)

// TODO: remove this w/ the ring buffer
#define MEM_NCRISC_INIT_IRAM_L1_SIZE MEM_NCRISC_FIRMWARE_SIZE

#define MEM_MAP_END (MEM_TRISC2_FIRMWARE_BASE + MEM_TRISC2_FIRMWARE_SIZE)

// Every address after MEM_MAP_END is a "scratch" address
Expand Down
5 changes: 3 additions & 2 deletions tt_metal/hw/inc/grayskull/dev_mem_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define MEM_BOOT_CODE_SIZE 4

#define MEM_BRISC_FIRMWARE_SIZE (10 * 1024 + MEM_BRISC_LOCAL_SIZE)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024 + MEM_NCRISC_LOCAL_SIZE)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024)
#define MEM_TRISC0_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC1_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC2_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
Expand All @@ -69,9 +69,10 @@
#define MEM_TRISC1_FIRMWARE_BASE (MEM_TRISC0_FIRMWARE_BASE + MEM_TRISC0_FIRMWARE_SIZE)
#define MEM_TRISC2_FIRMWARE_BASE (MEM_TRISC1_FIRMWARE_BASE + MEM_TRISC1_FIRMWARE_SIZE)

#define MEM_NCRISC_INIT_IRAM_L1_SIZE (MEM_NCRISC_FIRMWARE_SIZE + MEM_NCRISC_LOCAL_SIZE)
#define MEM_NCRISC_INIT_IRAM_L1_BASE (MEM_TRISC2_FIRMWARE_BASE + MEM_TRISC2_FIRMWARE_SIZE)

#define MEM_MAP_END (MEM_NCRISC_INIT_IRAM_L1_BASE + MEM_NCRISC_FIRMWARE_SIZE)
#define MEM_MAP_END (MEM_NCRISC_INIT_IRAM_L1_BASE + MEM_NCRISC_INIT_IRAM_L1_SIZE)

// Every address after MEM_MAP_END is a "scratch" address
// These can be used by FW during init, but aren't usable once FW reaches "ready"
Expand Down
5 changes: 3 additions & 2 deletions tt_metal/hw/inc/wormhole/dev_mem_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
// Firmware/kernel code holes
#define MEM_BOOT_CODE_SIZE 4
#define MEM_BRISC_FIRMWARE_SIZE (10 * 1024 + MEM_BRISC_LOCAL_SIZE)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024 + MEM_NCRISC_LOCAL_SIZE)
#define MEM_NCRISC_FIRMWARE_SIZE (16 * 1024)
#define MEM_TRISC0_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC1_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
#define MEM_TRISC2_FIRMWARE_SIZE (16 * 1024 + MEM_TRISC_LOCAL_SIZE)
Expand All @@ -69,9 +69,10 @@
#define MEM_TRISC1_FIRMWARE_BASE (MEM_TRISC0_FIRMWARE_BASE + MEM_TRISC0_FIRMWARE_SIZE)
#define MEM_TRISC2_FIRMWARE_BASE (MEM_TRISC1_FIRMWARE_BASE + MEM_TRISC1_FIRMWARE_SIZE)

#define MEM_NCRISC_INIT_IRAM_L1_SIZE (MEM_NCRISC_FIRMWARE_SIZE + MEM_NCRISC_LOCAL_SIZE)
#define MEM_NCRISC_INIT_IRAM_L1_BASE (MEM_TRISC2_FIRMWARE_BASE + MEM_TRISC2_FIRMWARE_SIZE)

#define MEM_MAP_END (MEM_NCRISC_INIT_IRAM_L1_BASE + MEM_NCRISC_FIRMWARE_SIZE)
#define MEM_MAP_END (MEM_NCRISC_INIT_IRAM_L1_BASE + MEM_NCRISC_INIT_IRAM_L1_SIZE)

// Every address after MEM_MAP_END is a "scratch" address
// These can be used by FW during init, but aren't usable once FW reaches "ready"
Expand Down
2 changes: 1 addition & 1 deletion tt_metal/impl/program/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void Program::populate_dispatch_data(Device *device) {
};
static const uint32_t processor_to_firmware_size[] = {
MEM_BRISC_FIRMWARE_SIZE,
MEM_NCRISC_FIRMWARE_SIZE,
MEM_NCRISC_INIT_IRAM_L1_SIZE,
MEM_TRISC0_FIRMWARE_SIZE,
MEM_TRISC1_FIRMWARE_SIZE,
MEM_TRISC2_FIRMWARE_SIZE,
Expand Down

0 comments on commit 32c62b9

Please sign in to comment.