GATOR_DEFINE_PROBE(mali_pm_status, TP_PROTO(unsigned int event_id, unsigned long long value)) { #define SHADER_PRESENT_LO 0x100 /* (RO) Shader core present bitmap, low word */ #define TILER_PRESENT_LO 0x110 /* (RO) Tiler core present bitmap, low word */ #define L2_PRESENT_LO 0x120 /* (RO) Level 2 cache present bitmap, low word */ #define BIT_AT(value, pos) ((value >> pos) & 1) switch (event_id) { case SHADER_PRESENT_LO: { unsigned long long changed_bitmask = previous_shader_bitmask ^ value; int pos; for (pos = 0; pos < NUM_PM_SHADER; ++pos) { if (BIT_AT(changed_bitmask, pos)) record_timeline_event(PM_SHADER_0 + pos, BIT_AT(value, pos) ? ACTIVITY_START : ACTIVITY_STOP); } previous_shader_bitmask = value; break; } case TILER_PRESENT_LO: { unsigned long long changed = previous_tiler_bitmask ^ value; if (BIT_AT(changed, 0)) record_timeline_event(PM_TILER_0, BIT_AT(value, 0) ? ACTIVITY_START : ACTIVITY_STOP); previous_tiler_bitmask = value; break; } case L2_PRESENT_LO: { unsigned long long changed = previous_l2_bitmask ^ value; if (BIT_AT(changed, 0)) record_timeline_event(PM_L2_0, BIT_AT(value, 0) ? ACTIVITY_START : ACTIVITY_STOP); if (BIT_AT(changed, 4)) record_timeline_event(PM_L2_1, BIT_AT(value, 4) ? ACTIVITY_START : ACTIVITY_STOP); previous_l2_bitmask = value; break; } default: /* No other blocks are supported at present */ break; } #undef SHADER_PRESENT_LO #undef TILER_PRESENT_LO #undef L2_PRESENT_LO #undef BIT_AT }
static size_t brle_decode(const unsigned char *buf, size_t nbits, unsigned char *outbuf) { size_t readp; size_t writep = 0; unsigned char bit; size_t runlen; for (readp = 0; readp < nbits; ++readp) { bit = BIT_AT(readp); ++readp; for (runlen = 0; BIT_AT(readp); ++readp) { runlen <<= 1; runlen |= 1; } PUT_BIT(bit); while (runlen--) PUT_BIT(bit); } return writep; }
static size_t brle_encode(const unsigned char *buf, size_t size, unsigned char *outbuf) { const size_t nbits = size * CHAR_BIT; size_t readp; size_t writep = 0; size_t len; size_t runlen; unsigned char bit; for (readp = 0; readp < nbits; /*empty*/) { bit = BIT_AT(readp); len = 1; while (readp + len < nbits) { if ((bit && BIT_AT(readp + len)) || (!bit && !BIT_AT(readp + len))) ++len; else break; } readp += len; do { PUT_BIT(bit); --len; runlen = ~0; while (runlen > len) runlen >>= 1; len -= runlen; while (runlen > 0) { PUT_BIT(1); runlen >>= 1; } PUT_BIT(0); } while (len > 0); } return writep; }
void cryptBuffer( unsigned char *buf, size_t size, unsigned short keyvalue, bool decode) { int n = 0; unsigned short key = n ^ keyvalue; for (int i = 0; i < size; i ++) { unsigned char xorkey = 0; if (key & 0x4000) xorkey |= 0x80; if (key & 0x1000) xorkey |= 0x40; if (key & 0x0800) xorkey |= 0x20; if (key & 0x0200) xorkey |= 0x10; if (key & 0x0080) xorkey |= 0x08; if (key & 0x0040) xorkey |= 0x04; if (key & 0x0002) xorkey |= 0x02; if (key & 0x0001) xorkey |= 0x01; if (!decode) buf[i] ^= xorkey; unsigned int k = ((buf[i] << 8) ^ key) << 16; unsigned int x = k; for (int j = 1; j < 32; j ++) x ^= k >> j; key = 0x0000; if (BIT_AT(x, 23)) key |= 0x8000; if (BIT_AT(k, 22)) key |= 0x4000; if (BIT_AT(k, 21)) key |= 0x2000; if (BIT_AT(k, 20)) key |= 0x1000; if (BIT_AT(k, 19)) key |= 0x0800; if (BIT_AT(k, 18)) key |= 0x0400; if (BIT_AT(k, 17) != BIT_AT(x, 31)) key |= 0x0200; if (BIT_AT(k, 16) != BIT_AT(x, 30)) key |= 0x0100; if (BIT_AT(k, 30) != BIT_AT(k, 29)) key |= 0x0080; if (BIT_AT(k, 29) != BIT_AT(k, 28)) key |= 0x0040; if (BIT_AT(k, 28) != BIT_AT(k, 27)) key |= 0x0020; if (BIT_AT(k, 27) != BIT_AT(k, 26)) key |= 0x0010; if (BIT_AT(k, 26) != BIT_AT(k, 25)) key |= 0x0008; if (BIT_AT(k, 25) != BIT_AT(k, 24)) key |= 0x0004; if (BIT_AT(k, 25) != BIT_AT(x, 26)) key |= 0x0002; if (BIT_AT(k, 24) != BIT_AT(x, 25)) key |= 0x0001; if (decode) buf[i] ^= xorkey; } }
unsigned char uart_getc() { while (mmio_read(UART0_FR) & BIT_AT(4)); return mmio_read(UART0_DR); }
void uart_putc(unsigned char byte) { while (mmio_read(UART0_FR) & BIT_AT(5)); mmio_write(UART0_DR, byte); }
void uart_init() { mmio_write(UART0_CR, 0x00000000); mmio_write(GPPUD, 0x00000000); delay(150); mmio_write(GPPUDCLK0, BIT_AT(14) | BIT_AT(15)); delay(150); mmio_write(GPPUDCLK0, 0x00000000); mmio_write(UART0_ICR, 0x7FF); mmio_write(UART0_IBRD, 1); mmio_write(UART0_FBRD, 40); mmio_write(UART0_LCRH, BIT_AT(4) | BIT_AT(5) | BIT_AT(6)); mmio_write(UART0_IMSC, BIT_AT(1) | BIT_AT(4) | BIT_AT(5) | BIT_AT(6) | BIT_AT(7) | BIT_AT(8) | BIT_AT(9) | BIT_AT(10)); mmio_write(UART0_CR, BIT_AT(0) | BIT_AT(8) | BIT_AT(9)); }