/* What the master hands the slave each frame (m_main.c, s_main.c). */ #ifndef C1JOB_H #define C1JOB_H #include #include "c1dec.h" #define C1_FB_BASE 0x100 /* word offset of stored row 0, after the 256-word line table */ typedef struct { const uint8_t *payload; int ref; /* planes index holding the reference; the frame decodes into ref ^ 1 */ } c1_job_t; extern uint8_t c1_plane_mem[2][C1_ROWS * C1_W * 3 / 2]; extern c1_planes c1_p[2]; extern c1_job_t c1_job; extern uint8_t c1_changed[C1_NMB]; extern uint8_t c1_prev[C1_NMB]; /* changed in the frame before; each CPU updates its own MBs */ extern uint8_t c1_mask[C1_NMB]; /* Cache-through alias of an SDRAM address (0x26xxxxxx): reads see the other CPU's writes. */ #define C1_THROUGH(p) ((__typeof__(&(p)[0]))((uintptr_t)(p) | 0x20000000u)) /* Associative purge (HM 8.4.7): a write to 0x40000000 | address drops that line if cached. */ static inline void c1_purge_lines(const void *a, unsigned bytes) { uintptr_t p = ((uintptr_t)a & 0x1FFFFFF0u) | 0x40000000u; uintptr_t e = ((uintptr_t)a + bytes + 15) & 0x1FFFFFF0u; for (e |= 0x40000000u; p < e; p += 16) *(volatile uint32_t *)p = 0; } /* Before decoding MBs [m0, m1) against planes pl: drop the cached lines the other CPU may * have made stale, i.e. the rows of the MBs [o0, o1) it wrote into pl last frame, as far as * this CPU's motion vectors (|v| <= 17 luma rows, 9 chroma) can reach. Lines nobody wrote * (lazy skip copies) are still valid; this CPU's own writes are write-through. */ static inline void c1_purge_band(const c1_planes *pl, int o0, int o1, int m0, int m1) { if (o0 >= o1) return; int y0 = (o0 / C1_MBX) * 16, y1 = ((o1 - 1) / C1_MBX + 1) * 16; int r0 = (m0 / C1_MBX) * 16 - 17, r1 = ((m1 - 1) / C1_MBX + 1) * 16 + 17; if (y0 < r0) y0 = r0; if (y1 > r1) y1 = r1; if (y0 < 0) y0 = 0; if (y1 > C1_ROWS) y1 = C1_ROWS; if (y0 >= y1) return; c1_purge_lines(pl->y + y0 * C1_W, (unsigned)(y1 - y0) * C1_W); int c0 = y0 / 2 - 1, c1 = (y1 + 1) / 2 + 1; if (c0 < 0) c0 = 0; if (c1 > C1_ROWS / 2) c1 = C1_ROWS / 2; c1_purge_lines(pl->cb + c0 * (C1_W / 2), (unsigned)(c1 - c0) * (C1_W / 2)); c1_purge_lines(pl->cr + c0 * (C1_W / 2), (unsigned)(c1 - c0) * (C1_W / 2)); } /* Spin without touching the bus: a register count-down, run from the cache. Polling a * 32X register back to back would hold the shared bus against the other CPU. */ static inline void c1_pause(void) { int n = 64; __asm__ volatile("1: dt %0\n\tbf 1b" : "+r"(n)); } #endif