| .. | .. |
|---|
| 40 | 40 | typedef unsigned int cycles_t; |
|---|
| 41 | 41 | |
|---|
| 42 | 42 | /* |
|---|
| 43 | | - * On R4000/R4400 before version 5.0 an erratum exists such that if the |
|---|
| 44 | | - * cycle counter is read in the exact moment that it is matching the |
|---|
| 45 | | - * compare register, no interrupt will be generated. |
|---|
| 43 | + * On R4000/R4400 an erratum exists such that if the cycle counter is |
|---|
| 44 | + * read in the exact moment that it is matching the compare register, |
|---|
| 45 | + * no interrupt will be generated. |
|---|
| 46 | 46 | * |
|---|
| 47 | 47 | * There is a suggested workaround and also the erratum can't strike if |
|---|
| 48 | 48 | * the compare interrupt isn't being used as the clock source device. |
|---|
| .. | .. |
|---|
| 63 | 63 | if (!__builtin_constant_p(cpu_has_counter)) |
|---|
| 64 | 64 | asm volatile("" : "=m" (cpu_data[0].options)); |
|---|
| 65 | 65 | if (likely(cpu_has_counter && |
|---|
| 66 | | - prid >= (PRID_IMP_R4000 | PRID_REV_ENCODE_44(5, 0)))) |
|---|
| 66 | + prid > (PRID_IMP_R4000 | PRID_REV_ENCODE_44(15, 15)))) |
|---|
| 67 | 67 | return 1; |
|---|
| 68 | 68 | else |
|---|
| 69 | 69 | return 0; |
|---|
| .. | .. |
|---|
| 76 | 76 | else |
|---|
| 77 | 77 | return 0; /* no usable counter */ |
|---|
| 78 | 78 | } |
|---|
| 79 | +#define get_cycles get_cycles |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | /* |
|---|
| 81 | 82 | * Like get_cycles - but where c0_count is not available we desperately |
|---|
| 82 | 83 | * use c0_random in an attempt to get at least a little bit of entropy. |
|---|
| 83 | | - * |
|---|
| 84 | | - * R6000 and R6000A neither have a count register nor a random register. |
|---|
| 85 | | - * That leaves no entropy source in the CPU itself. |
|---|
| 86 | 84 | */ |
|---|
| 87 | 85 | static inline unsigned long random_get_entropy(void) |
|---|
| 88 | 86 | { |
|---|
| 89 | | - unsigned int prid = read_c0_prid(); |
|---|
| 90 | | - unsigned int imp = prid & PRID_IMP_MASK; |
|---|
| 87 | + unsigned int c0_random; |
|---|
| 91 | 88 | |
|---|
| 92 | | - if (can_use_mips_counter(prid)) |
|---|
| 89 | + if (can_use_mips_counter(read_c0_prid())) |
|---|
| 93 | 90 | return read_c0_count(); |
|---|
| 94 | | - else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A)) |
|---|
| 95 | | - return read_c0_random(); |
|---|
| 91 | + |
|---|
| 92 | + if (cpu_has_3kex) |
|---|
| 93 | + c0_random = (read_c0_random() >> 8) & 0x3f; |
|---|
| 96 | 94 | else |
|---|
| 97 | | - return 0; /* no usable register */ |
|---|
| 95 | + c0_random = read_c0_random() & 0x3f; |
|---|
| 96 | + return (random_get_entropy_fallback() << 6) | (0x3f - c0_random); |
|---|
| 98 | 97 | } |
|---|
| 99 | 98 | #define random_get_entropy random_get_entropy |
|---|
| 100 | 99 | |
|---|