Skip to content

Commit

Permalink
BH: Add 2M TLB window support for driver use
Browse files Browse the repository at this point in the history
- Add 2M PCIe TLB window register layout.
- Claim topmost 2M window as the driver's.
- Map topmost 2M window and window config registers.
- Add program_tlb() and noc_read32() functions.
  • Loading branch information
joelsmithTT committed Jan 22, 2025
1 parent d2806af commit bce2a38
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
83 changes: 83 additions & 0 deletions blackhole.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,90 @@

#define MAX_MRRS 4096

#define TLB_2M_WINDOW_COUNT 202
#define TLB_2M_SHIFT 21
#define TLB_2M_REG_SIZE 12
#define TLB_2M_WINDOW_SIZE (1 << TLB_2M_SHIFT)
#define TLB_2M_WINDOW_MASK (TLB_2M_WINDOW_SIZE - 1)

#define TLB_REGS_START 0x1FC00000 // BAR0
#define TLB_REGS_LEN 0x00001000 // Covers all TLB registers

#define KERNEL_TLB_INDEX (TLB_2M_WINDOW_COUNT - 1) // Last 2M window is ours
#define KERNEL_TLB_START (KERNEL_TLB_INDEX * TLB_2M_WINDOW_SIZE)
#define KERNEL_TLB_LEN TLB_2M_WINDOW_SIZE

struct TLB_2M_REG {
union {
struct {
u32 low32;
u32 mid32;
u32 high32;
};
struct {
u64 address : 43;
u64 x_end : 6;
u64 y_end : 6;
u64 x_start : 6;
u64 y_start : 6;
u64 noc : 2;
u64 multicast : 1;
u64 ordering : 2;
u64 linked : 1;
u64 use_static_vc : 1;
u64 stream_header : 1;
u64 static_vc : 3;
u64 reserved : 18;
};
};
};

static u64 program_tlb(struct blackhole_device *bh, u32 x, u32 y, u64 addr) {
struct TLB_2M_REG conf = {0};
u8 __iomem *regs = bh->tlb_regs + (KERNEL_TLB_INDEX * TLB_2M_REG_SIZE);

conf.address = addr >> TLB_2M_SHIFT;
conf.x_end = x;
conf.y_end = y;

mb();
iowrite32(conf.low32, regs + 0);
iowrite32(conf.mid32, regs + 4);
iowrite32(conf.high32, regs + 8);
mb();

return addr & TLB_2M_WINDOW_MASK;
}

static u32 noc_read32(struct blackhole_device *bh, u32 x, u32 y, u64 addr) {
u64 offset;
u32 val;

mutex_lock(&bh->mutex);

offset = program_tlb(bh, x, y, addr);
val = ioread32(bh->kernel_tlb + offset);

mutex_unlock(&bh->mutex);

return val;
}

static bool blackhole_init(struct tenstorrent_device *tt_dev) {
struct blackhole_device *bh = tt_dev_to_bh_dev(tt_dev);

bh->tlb_regs = pci_iomap_range(bh->tt.pdev, 0, TLB_REGS_START, TLB_REGS_LEN);
bh->kernel_tlb = pci_iomap_range(bh->tt.pdev, 0, KERNEL_TLB_START, KERNEL_TLB_LEN);

if (!bh->tlb_regs || !bh->kernel_tlb) {
if (bh->tlb_regs)
pci_iounmap(bh->tt.pdev, bh->tlb_regs);

if (bh->kernel_tlb)
pci_iounmap(bh->tt.pdev, bh->kernel_tlb);
return false;
}

return true;
}

Expand Down
4 changes: 4 additions & 0 deletions blackhole.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

struct blackhole_device {
struct tenstorrent_device tt;

struct mutex mutex; // Guards access to kernel_tlb
u8 __iomem *tlb_regs; // All TLB registers
u8 __iomem *kernel_tlb; // Topmost 2M window, reserved for kernel
};

#define tt_dev_to_bh_dev(ttdev) \
Expand Down

0 comments on commit bce2a38

Please sign in to comment.