|
21 | 21 |
|
22 | 22 | #include "cxl.h" |
23 | 23 |
|
24 | | -static struct cxl_sste* find_free_sste(struct cxl_sste *primary_group, |
25 | | - unsigned int *lru) |
| 24 | +/* This finds a free SSTE for the given SLB */ |
| 25 | +static struct cxl_sste* find_free_sste(struct cxl_context *ctx, |
| 26 | + struct copro_slb *slb) |
26 | 27 | { |
| 28 | + struct cxl_sste *primary, *sste; |
| 29 | + unsigned int mask = (ctx->sst_size >> 7) - 1; /* SSTP0[SegTableSize] */ |
27 | 30 | unsigned int entry; |
28 | | - struct cxl_sste *sste, *group = primary_group; |
| 31 | + unsigned int hash; |
| 32 | + |
| 33 | + if (slb->vsid & SLB_VSID_B_1T) |
| 34 | + hash = (slb->esid >> SID_SHIFT_1T) & mask; |
| 35 | + else /* 256M */ |
| 36 | + hash = (slb->esid >> SID_SHIFT) & mask; |
29 | 37 |
|
30 | | - for (entry = 0; entry < 8; entry++) { |
31 | | - sste = group + entry; |
| 38 | + primary = ctx->sstp + (hash << 3); |
| 39 | + |
| 40 | + for (entry = 0, sste = primary; entry < 8; entry++, sste++) { |
32 | 41 | if (!(be64_to_cpu(sste->esid_data) & SLB_ESID_V)) |
33 | 42 | return sste; |
34 | 43 | } |
| 44 | + |
35 | 45 | /* Nothing free, select an entry to cast out */ |
36 | | - sste = primary_group + *lru; |
37 | | - *lru = (*lru + 1) & 0x7; |
| 46 | + sste = primary + ctx->sst_lru; |
| 47 | + ctx->sst_lru = (ctx->sst_lru + 1) & 0x7; |
38 | 48 |
|
39 | 49 | return sste; |
40 | 50 | } |
41 | 51 |
|
42 | 52 | static void cxl_load_segment(struct cxl_context *ctx, struct copro_slb *slb) |
43 | 53 | { |
44 | 54 | /* mask is the group index, we search primary and secondary here. */ |
45 | | - unsigned int mask = (ctx->sst_size >> 7)-1; /* SSTP0[SegTableSize] */ |
46 | 55 | struct cxl_sste *sste; |
47 | | - unsigned int hash; |
48 | 56 | unsigned long flags; |
49 | 57 |
|
50 | | - |
51 | | - if (slb->vsid & SLB_VSID_B_1T) |
52 | | - hash = (slb->esid >> SID_SHIFT_1T) & mask; |
53 | | - else /* 256M */ |
54 | | - hash = (slb->esid >> SID_SHIFT) & mask; |
55 | | - |
56 | 58 | spin_lock_irqsave(&ctx->sste_lock, flags); |
57 | | - sste = find_free_sste(ctx->sstp + (hash << 3), &ctx->sst_lru); |
| 59 | + sste = find_free_sste(ctx, slb); |
58 | 60 |
|
59 | 61 | pr_devel("CXL Populating SST[%li]: %#llx %#llx\n", |
60 | 62 | sste - ctx->sstp, slb->vsid, slb->esid); |
|
0 commit comments