int __BS(translate)(void *v, bus_addr_t addr, bus_size_t len, int flags, struct mips_bus_space_translation *mbst) { bus_addr_t end = addr + (len - 1); #if CHIP_ALIGN_STRIDE != 0 int linear = flags & BUS_SPACE_MAP_LINEAR; /* * Can't map xxx space linearly. */ if (linear) return (EOPNOTSUPP); #endif #ifdef CHIP_W1_BUS_START if (addr >= CHIP_W1_BUS_START(v) && end <= CHIP_W1_BUS_END(v)) return (__BS(get_window)(v, 0, mbst)); #endif #ifdef CHIP_W2_BUS_START if (addr >= CHIP_W2_BUS_START(v) && end <= CHIP_W2_BUS_END(v)) return (__BS(get_window)(v, 1, mbst)); #endif #ifdef CHIP_W3_BUS_START if (addr >= CHIP_W3_BUS_START(v) && end <= CHIP_W3_BUS_END(v)) return (__BS(get_window)(v, 2, mbst)); #endif #ifdef EXTENT_DEBUG printf("\n"); #ifdef CHIP_W1_BUS_START printf("%s: window[1]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W1_BUS_START(v), (u_long)CHIP_W1_BUS_END(v)); #endif #ifdef CHIP_W2_BUS_START printf("%s: window[2]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W2_BUS_START(v), (u_long)CHIP_W2_BUS_END(v)); #endif #ifdef CHIP_W3_BUS_START printf("%s: window[3]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W3_BUS_START(v), (u_long)CHIP_W3_BUS_END(v)); #endif #endif /* EXTENT_DEBUG */ /* No translation. */ return (EINVAL); }
void __C(CHIP,_mem_unmap)( void *v, bus_space_handle_t memh, bus_size_t memsize, int acct) { bus_addr_t memaddr; int error; if (acct == 0) return; #ifdef EXTENT_DEBUG printf("mem: freeing handle 0x%lx for 0x%lx\n", memh, memsize); #endif memaddr = memh - ALPHA_PHYS_TO_K0SEG(CHIP_MEM_SYS_START(v)); #ifdef EXTENT_DEBUG printf("mem: freeing 0x%lx to 0x%lx\n", memaddr, memaddr + memsize - 1); #endif error = extent_free(CHIP_MEM_EXTENT(v), memaddr, memsize, EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0)); if (error) { printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n", __S(__C(CHIP,_mem_unmap)), memaddr, memaddr + memsize - 1, error); #ifdef EXTENT_DEBUG extent_print(CHIP_MEM_EXTENT(v)); #endif } }
int __C(CHIP,_mem_get_window)( void *v, int window, struct alpha_bus_space_translation *abst) { switch (window) { case 0: abst->abst_bus_start = 0; abst->abst_bus_end = 0xffffffffUL; abst->abst_sys_start = CHIP_MEM_SYS_START(v); abst->abst_sys_end = CHIP_MEM_SYS_START(v) + abst->abst_bus_end; abst->abst_addr_shift = 0; abst->abst_size_shift = 0; abst->abst_flags = ABST_DENSE|ABST_BWX; break; default: panic(__S(__C(CHIP,_mem_get_window)) ": invalid window %d", window); } return (0); }
static inline void __C(CHIP,_mem_write_8)( void *v, bus_space_handle_t memh, bus_size_t off, uint64_t val) { /* XXX XXX XXX */ panic("%s not implemented", __S(__C(CHIP,_mem_write_8))); alpha_mb(); }
static inline uint64_t __C(CHIP,_mem_read_8)( void *v, bus_space_handle_t memh, bus_size_t off) { alpha_mb(); /* XXX XXX XXX */ panic("%s not implemented", __S(__C(CHIP,_mem_read_8))); }
static inline uint32_t __C(CHIP,_mem_read_4)( void *v, bus_space_handle_t memh, bus_size_t off) { bus_addr_t addr; addr = memh + off; #ifdef DIAGNOSTIC if (addr & 3) panic(__S(__C(CHIP,_mem_read_4)) ": addr 0x%lx not aligned", addr); #endif alpha_mb(); return (*(uint32_t *)addr); }
int __BS(get_window)(void *v, int window, struct mips_bus_space_translation *mbst) { switch (window) { #ifdef CHIP_W1_BUS_START case 0: mbst->mbst_bus_start = CHIP_W1_BUS_START(v); mbst->mbst_bus_end = CHIP_W1_BUS_END(v); mbst->mbst_sys_start = CHIP_W1_SYS_START(v); mbst->mbst_sys_end = CHIP_W1_SYS_END(v); mbst->mbst_align_stride = CHIP_ALIGN_STRIDE; mbst->mbst_flags = 0; break; #endif #ifdef CHIP_W2_BUS_START case 1: mbst->mbst_bus_start = CHIP_W2_BUS_START(v); mbst->mbst_bus_end = CHIP_W2_BUS_END(v); mbst->mbst_sys_start = CHIP_W2_SYS_START(v); mbst->mbst_sys_end = CHIP_W2_SYS_END(v); mbst->mbst_align_stride = CHIP_ALIGN_STRIDE; mbst->mbst_flags = 0; break; #endif #ifdef CHIP_W3_BUS_START case 2: mbst->mbst_bus_start = CHIP_W3_BUS_START(v); mbst->mbst_bus_end = CHIP_W3_BUS_END(v); mbst->mbst_sys_start = CHIP_W3_SYS_START(v); mbst->mbst_sys_end = CHIP_W3_SYS_END(v); mbst->mbst_align_stride = CHIP_ALIGN_STRIDE; mbst->mbst_flags = 0; break; #endif default: panic(__S(__BS(get_window)) ": invalid window %d", window); } return (0); }
static inline void __C(CHIP,_mem_write_4)( void *v, bus_space_handle_t memh, bus_size_t off, uint32_t val) { bus_addr_t addr; addr = memh + off; #ifdef DIAGNOSTIC if (addr & 3) panic(__S(__C(CHIP,_mem_write_4)) ": addr 0x%lx not aligned", addr); #endif *(uint32_t *)addr = val; alpha_mb(); }
TEST(cstr, simd_match_ctext_vchar) { #define N 300 #define P 23 int i; char buf[N] = {[0 ... N - 1] = 0xff }; /* fill in with valid chars */ BUILD_BUG_ON(N < P + 257 || P < 1); /* All the allowed characters are matched. */ for (i = 0; i <= 0xff; ++i) if (i == 9 || (i >= 0x20 && i != 0x7f)) buf[P + i] = i; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == N); /* Check short strings. */ EXPECT_TRUE(tfw_match_ctext_vchar(buf + P - 1, 4) == 4); EXPECT_TRUE(tfw_match_ctext_vchar(buf + P - 1, 15) == 15); EXPECT_TRUE(tfw_match_ctext_vchar(buf + P - 1, 29) == 29); /* Check not allowed characters. */ buf[P + 0x7f] = 0x7f; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == P + 0x7f); buf[P + 0x1f] = 0x1f; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == P + 0x1f); buf[P + 0xa] = 0xa; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == P + 0xa); buf[P + 8] = 8; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == P + 8); buf[P + 0] = 0; EXPECT_TRUE(tfw_match_ctext_vchar(buf, N) == P); #undef P #undef N #define __S(s) s, sizeof(s) - 1 __test_ctext_vchar(__S("")); __test_ctext_vchar(__S(" ")); __test_ctext_vchar(__S("\x08")); __test_ctext_vchar(__S("a\x00z")); __test_ctext_vchar(__S(" \tx\rz")); __test_ctext_vchar(__S("\t !?@_`~>^Aa\x80\xff\x81\xfe\x00\xa\x1f\x1e")); __test_ctext_vchar(__S("\t !?@_`~>^A}a\x80\xff\x81" "\xfe\xaa\\Z+'\x7f\x00\x08\xa\x1f\x1\x1e")); __test_ctext_vchar(__S("\t !?@_`~>^A}a\x80\xff\x81" "\xfe\xaa\\Zz09+'\x7f\x00\x08\xa\x1f\x1\x1e")); __test_ctext_vchar(__S("123456789_123456789_123456789_123456789_" "abc\x7fmdef")); __test_ctext_vchar(__S("123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "abc\x7mdef")); __test_ctext_vchar(__S("123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "abcmdef\x0")); __test_ctext_vchar(__S("123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "123456789_123456789_123456789_123456789_" "a\x6pbcmdef")); #undef __S }
void __C(CHIP,_bus_mem_init)(bus_space_tag_t t, void *v) { #ifdef CHIP_D_MEM_W1_SYS_START struct extent *dex; #endif struct extent *sex; /* * Initialize the bus space tag. */ /* cookie */ t->abs_cookie = v; /* mapping/unmapping */ t->abs_map = __C(CHIP,_mem_map); t->abs_unmap = __C(CHIP,_mem_unmap); t->abs_subregion = __C(CHIP,_mem_subregion); t->abs_translate = __C(CHIP,_mem_translate); t->abs_get_window = __C(CHIP,_mem_get_window); /* allocation/deallocation */ t->abs_alloc = __C(CHIP,_mem_alloc); t->abs_free = __C(CHIP,_mem_free); /* get kernel virtual address */ t->abs_vaddr = __C(CHIP,_mem_vaddr); /* mmap for user */ t->abs_mmap = __C(CHIP,_mem_mmap); /* barrier */ t->abs_barrier = __C(CHIP,_mem_barrier); /* read (single) */ t->abs_r_1 = __C(CHIP,_mem_read_1); t->abs_r_2 = __C(CHIP,_mem_read_2); t->abs_r_4 = __C(CHIP,_mem_read_4); t->abs_r_8 = __C(CHIP,_mem_read_8); /* read multiple */ t->abs_rm_1 = __C(CHIP,_mem_read_multi_1); t->abs_rm_2 = __C(CHIP,_mem_read_multi_2); t->abs_rm_4 = __C(CHIP,_mem_read_multi_4); t->abs_rm_8 = __C(CHIP,_mem_read_multi_8); /* read region */ t->abs_rr_1 = __C(CHIP,_mem_read_region_1); t->abs_rr_2 = __C(CHIP,_mem_read_region_2); t->abs_rr_4 = __C(CHIP,_mem_read_region_4); t->abs_rr_8 = __C(CHIP,_mem_read_region_8); /* write (single) */ t->abs_w_1 = __C(CHIP,_mem_write_1); t->abs_w_2 = __C(CHIP,_mem_write_2); t->abs_w_4 = __C(CHIP,_mem_write_4); t->abs_w_8 = __C(CHIP,_mem_write_8); /* write multiple */ t->abs_wm_1 = __C(CHIP,_mem_write_multi_1); t->abs_wm_2 = __C(CHIP,_mem_write_multi_2); t->abs_wm_4 = __C(CHIP,_mem_write_multi_4); t->abs_wm_8 = __C(CHIP,_mem_write_multi_8); /* write region */ t->abs_wr_1 = __C(CHIP,_mem_write_region_1); t->abs_wr_2 = __C(CHIP,_mem_write_region_2); t->abs_wr_4 = __C(CHIP,_mem_write_region_4); t->abs_wr_8 = __C(CHIP,_mem_write_region_8); /* set multiple */ t->abs_sm_1 = __C(CHIP,_mem_set_multi_1); t->abs_sm_2 = __C(CHIP,_mem_set_multi_2); t->abs_sm_4 = __C(CHIP,_mem_set_multi_4); t->abs_sm_8 = __C(CHIP,_mem_set_multi_8); /* set region */ t->abs_sr_1 = __C(CHIP,_mem_set_region_1); t->abs_sr_2 = __C(CHIP,_mem_set_region_2); t->abs_sr_4 = __C(CHIP,_mem_set_region_4); t->abs_sr_8 = __C(CHIP,_mem_set_region_8); /* copy */ t->abs_c_1 = __C(CHIP,_mem_copy_region_1); t->abs_c_2 = __C(CHIP,_mem_copy_region_2); t->abs_c_4 = __C(CHIP,_mem_copy_region_4); t->abs_c_8 = __C(CHIP,_mem_copy_region_8); #ifdef CHIP_D_MEM_W1_SYS_START /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */ dex = extent_create(__S(__C(CHIP,_bus_dmem)), 0x0UL, 0xffffffffffffffffUL, (void *)CHIP_D_MEM_EX_STORE(v), CHIP_D_MEM_EX_STORE_SIZE(v), EX_NOWAIT); extent_alloc_region(dex, 0, 0xffffffffffffffffUL, EX_NOWAIT); #ifdef CHIP_D_MEM_W1_BUS_START #ifdef EXTENT_DEBUG printf("dmem: freeing from 0x%lx to 0x%lx\n", CHIP_D_MEM_W1_BUS_START(v), CHIP_D_MEM_W1_BUS_END(v)); #endif extent_free(dex, CHIP_D_MEM_W1_BUS_START(v), CHIP_D_MEM_W1_BUS_END(v) - CHIP_D_MEM_W1_BUS_START(v) + 1, EX_NOWAIT); #endif #ifdef EXTENT_DEBUG extent_print(dex); #endif CHIP_D_MEM_EXTENT(v) = dex; #endif /* CHIP_D_MEM_W1_SYS_START */ /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */ sex = extent_create(__S(__C(CHIP,_bus_smem)), 0x0UL, 0xffffffffffffffffUL, (void *)CHIP_S_MEM_EX_STORE(v), CHIP_S_MEM_EX_STORE_SIZE(v), EX_NOWAIT); extent_alloc_region(sex, 0, 0xffffffffffffffffUL, EX_NOWAIT); #ifdef CHIP_S_MEM_W1_BUS_START #ifdef EXTENT_DEBUG printf("smem: freeing from 0x%lx to 0x%lx\n", CHIP_S_MEM_W1_BUS_START(v), CHIP_S_MEM_W1_BUS_END(v)); #endif extent_free(sex, CHIP_S_MEM_W1_BUS_START(v), CHIP_S_MEM_W1_BUS_END(v) - CHIP_S_MEM_W1_BUS_START(v) + 1, EX_NOWAIT); #endif #ifdef CHIP_S_MEM_W2_BUS_START if (CHIP_S_MEM_W2_BUS_START(v) != CHIP_S_MEM_W1_BUS_START(v)) { #ifdef EXTENT_DEBUG printf("smem: freeing from 0x%lx to 0x%lx\n", CHIP_S_MEM_W2_BUS_START(v), CHIP_S_MEM_W2_BUS_END(v)); #endif extent_free(sex, CHIP_S_MEM_W2_BUS_START(v), CHIP_S_MEM_W2_BUS_END(v) - CHIP_S_MEM_W2_BUS_START(v) + 1, EX_NOWAIT); } else { #ifdef EXTENT_DEBUG printf("smem: window 2 (0x%lx to 0x%lx) overlaps window 1\n", CHIP_S_MEM_W2_BUS_START(v), CHIP_S_MEM_W2_BUS_END(v)); #endif } #endif #ifdef CHIP_S_MEM_W3_BUS_START if (CHIP_S_MEM_W3_BUS_START(v) != CHIP_S_MEM_W1_BUS_START(v) && CHIP_S_MEM_W3_BUS_START(v) != CHIP_S_MEM_W2_BUS_START(v)) { #ifdef EXTENT_DEBUG printf("smem: freeing from 0x%lx to 0x%lx\n", CHIP_S_MEM_W3_BUS_START(v), CHIP_S_MEM_W3_BUS_END(v)); #endif extent_free(sex, CHIP_S_MEM_W3_BUS_START(v), CHIP_S_MEM_W3_BUS_END(v) - CHIP_S_MEM_W3_BUS_START(v) + 1, EX_NOWAIT); } else { #ifdef EXTENT_DEBUG printf("smem: window 2 (0x%lx to 0x%lx) overlaps window 1\n", CHIP_S_MEM_W2_BUS_START(v), CHIP_S_MEM_W2_BUS_END(v)); #endif } #endif #ifdef EXTENT_DEBUG extent_print(sex); #endif CHIP_S_MEM_EXTENT(v) = sex; }
void __C(CHIP,_bus_mem_init)( bus_space_tag_t t, void *v) { struct extent *ex; /* * Initialize the bus space tag. */ /* cookie */ t->abs_cookie = v; /* mapping/unmapping */ t->abs_map = __C(CHIP,_mem_map); t->abs_unmap = __C(CHIP,_mem_unmap); t->abs_subregion = __C(CHIP,_mem_subregion); t->abs_translate = __C(CHIP,_mem_translate); t->abs_get_window = __C(CHIP,_mem_get_window); /* allocation/deallocation */ t->abs_alloc = __C(CHIP,_mem_alloc); t->abs_free = __C(CHIP,_mem_free); /* get kernel virtual address */ t->abs_vaddr = __C(CHIP,_mem_vaddr); /* mmap for user */ t->abs_mmap = __C(CHIP,_mem_mmap); /* barrier */ t->abs_barrier = __C(CHIP,_mem_barrier); /* read (single) */ t->abs_r_1 = __C(CHIP,_mem_read_1); t->abs_r_2 = __C(CHIP,_mem_read_2); t->abs_r_4 = __C(CHIP,_mem_read_4); t->abs_r_8 = __C(CHIP,_mem_read_8); /* read multiple */ t->abs_rm_1 = __C(CHIP,_mem_read_multi_1); t->abs_rm_2 = __C(CHIP,_mem_read_multi_2); t->abs_rm_4 = __C(CHIP,_mem_read_multi_4); t->abs_rm_8 = __C(CHIP,_mem_read_multi_8); /* read region */ t->abs_rr_1 = __C(CHIP,_mem_read_region_1); t->abs_rr_2 = __C(CHIP,_mem_read_region_2); t->abs_rr_4 = __C(CHIP,_mem_read_region_4); t->abs_rr_8 = __C(CHIP,_mem_read_region_8); /* write (single) */ t->abs_w_1 = __C(CHIP,_mem_write_1); t->abs_w_2 = __C(CHIP,_mem_write_2); t->abs_w_4 = __C(CHIP,_mem_write_4); t->abs_w_8 = __C(CHIP,_mem_write_8); /* write multiple */ t->abs_wm_1 = __C(CHIP,_mem_write_multi_1); t->abs_wm_2 = __C(CHIP,_mem_write_multi_2); t->abs_wm_4 = __C(CHIP,_mem_write_multi_4); t->abs_wm_8 = __C(CHIP,_mem_write_multi_8); /* write region */ t->abs_wr_1 = __C(CHIP,_mem_write_region_1); t->abs_wr_2 = __C(CHIP,_mem_write_region_2); t->abs_wr_4 = __C(CHIP,_mem_write_region_4); t->abs_wr_8 = __C(CHIP,_mem_write_region_8); /* set multiple */ t->abs_sm_1 = __C(CHIP,_mem_set_multi_1); t->abs_sm_2 = __C(CHIP,_mem_set_multi_2); t->abs_sm_4 = __C(CHIP,_mem_set_multi_4); t->abs_sm_8 = __C(CHIP,_mem_set_multi_8); /* set region */ t->abs_sr_1 = __C(CHIP,_mem_set_region_1); t->abs_sr_2 = __C(CHIP,_mem_set_region_2); t->abs_sr_4 = __C(CHIP,_mem_set_region_4); t->abs_sr_8 = __C(CHIP,_mem_set_region_8); /* copy */ t->abs_c_1 = __C(CHIP,_mem_copy_region_1); t->abs_c_2 = __C(CHIP,_mem_copy_region_2); t->abs_c_4 = __C(CHIP,_mem_copy_region_4); t->abs_c_8 = __C(CHIP,_mem_copy_region_8); ex = extent_create(__S(__C(CHIP,_bus_mem)), 0x0UL, 0xffffffffUL, (void *)CHIP_MEM_EX_STORE(v), CHIP_MEM_EX_STORE_SIZE(v), EX_NOWAIT|EX_NOCOALESCE); CHIP_MEM_EXTENT(v) = ex; }
void __BS(unmap)(void *v, bus_space_handle_t h, bus_size_t size, int acct) { #ifdef CHIP_EXTENT bus_addr_t addr; int error; if (acct == 0) return; #ifdef EXTENT_DEBUG printf("xxx: freeing handle 0x%lx for 0x%lx\n", h, size); #endif if (h >= MIPS_KSEG0_START && h < MIPS_KSEG1_START) h = MIPS_KSEG0_TO_PHYS(h); else h = MIPS_KSEG1_TO_PHYS(h); #ifdef CHIP_W1_BUS_START if (h >= CHIP_W1_SYS_START(v) && h <= CHIP_W1_SYS_END(v)) { addr = CHIP_W1_BUS_START(v) + (h - CHIP_W1_SYS_START(v)); } else #endif #ifdef CHIP_W2_BUS_START if (h >= CHIP_W2_SYS_START(v) && h <= CHIP_W2_SYS_END(v)) { addr = CHIP_W2_BUS_START(v) + (h - CHIP_W2_SYS_START(v)); } else #endif #ifdef CHIP_W3_BUS_START if (h >= CHIP_W3_SYS_START(v) && h <= CHIP_W3_SYS_END(v)) { addr = CHIP_W3_BUS_START(v) + (h - CHIP_W3_SYS_START(v)); } else #endif { printf("\n"); #ifdef CHIP_W1_BUS_START printf("%s: sys window[1]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W1_SYS_START(v), (u_long)CHIP_W1_SYS_END(v)); #endif #ifdef CHIP_W2_BUS_START printf("%s: sys window[2]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W2_SYS_START(v), (u_long)CHIP_W2_SYS_END(v)); #endif #ifdef CHIP_W3_BUS_START printf("%s: sys window[3]=0x%lx-0x%lx\n", __S(__BS(map)), (u_long)CHIP_W3_SYS_START(v), (u_long)CHIP_W3_SYS_END(v)); #endif panic("%s: don't know how to unmap %lx", __S(__BS(unmap)), h); } #ifdef EXTENT_DEBUG printf("xxx: freeing 0x%lx to 0x%lx\n", addr, addr + size - 1); #endif error = extent_free(CHIP_EXTENT(v), addr, size, EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0)); if (error) { printf("%s: WARNING: could not unmap 0x%lx-0x%lx (error %d)\n", __S(__BS(unmap)), addr, addr + size - 1, error); #ifdef EXTENT_DEBUG extent_print(CHIP_EXTENT(v)); #endif } #endif /* CHIP_EXTENT */ }
void __BS(init)(bus_space_tag_t t, void *v) { #ifdef CHIP_EXTENT struct extent *ex; #endif /* * Initialize the bus space tag. */ /* cookie */ t->bs_cookie = v; /* mapping/unmapping */ t->bs_map = __BS(map); t->bs_unmap = __BS(unmap); t->bs_subregion = __BS(subregion); t->bs_translate = __BS(translate); t->bs_get_window = __BS(get_window); /* allocation/deallocation */ t->bs_alloc = __BS(alloc); t->bs_free = __BS(free); /* get kernel virtual address */ t->bs_vaddr = __BS(vaddr); /* mmap for user */ t->bs_mmap = __BS(mmap); /* barrier */ t->bs_barrier = __BS(barrier); /* read (single) */ t->bs_r_1 = __BS(read_1); t->bs_r_2 = __BS(read_2); t->bs_r_4 = __BS(read_4); t->bs_r_8 = __BS(read_8); /* read multiple */ t->bs_rm_1 = __BS(read_multi_1); t->bs_rm_2 = __BS(read_multi_2); t->bs_rm_4 = __BS(read_multi_4); t->bs_rm_8 = __BS(read_multi_8); /* read region */ t->bs_rr_1 = __BS(read_region_1); t->bs_rr_2 = __BS(read_region_2); t->bs_rr_4 = __BS(read_region_4); t->bs_rr_8 = __BS(read_region_8); /* write (single) */ t->bs_w_1 = __BS(write_1); t->bs_w_2 = __BS(write_2); t->bs_w_4 = __BS(write_4); t->bs_w_8 = __BS(write_8); /* write multiple */ t->bs_wm_1 = __BS(write_multi_1); t->bs_wm_2 = __BS(write_multi_2); t->bs_wm_4 = __BS(write_multi_4); t->bs_wm_8 = __BS(write_multi_8); /* write region */ t->bs_wr_1 = __BS(write_region_1); t->bs_wr_2 = __BS(write_region_2); t->bs_wr_4 = __BS(write_region_4); t->bs_wr_8 = __BS(write_region_8); /* set multiple */ t->bs_sm_1 = __BS(set_multi_1); t->bs_sm_2 = __BS(set_multi_2); t->bs_sm_4 = __BS(set_multi_4); t->bs_sm_8 = __BS(set_multi_8); /* set region */ t->bs_sr_1 = __BS(set_region_1); t->bs_sr_2 = __BS(set_region_2); t->bs_sr_4 = __BS(set_region_4); t->bs_sr_8 = __BS(set_region_8); /* copy */ t->bs_c_1 = __BS(copy_region_1); t->bs_c_2 = __BS(copy_region_2); t->bs_c_4 = __BS(copy_region_4); t->bs_c_8 = __BS(copy_region_8); #ifdef CHIP_NEED_STREAM /* read (single), stream */ t->bs_rs_1 = __BS(read_stream_1); t->bs_rs_2 = __BS(read_stream_2); t->bs_rs_4 = __BS(read_stream_4); t->bs_rs_8 = __BS(read_stream_8); /* read multiple, stream */ t->bs_rms_1 = __BS(read_multi_stream_1); t->bs_rms_2 = __BS(read_multi_stream_2); t->bs_rms_4 = __BS(read_multi_stream_4); t->bs_rms_8 = __BS(read_multi_stream_8); /* read region, stream */ t->bs_rrs_1 = __BS(read_region_stream_1); t->bs_rrs_2 = __BS(read_region_stream_2); t->bs_rrs_4 = __BS(read_region_stream_4); t->bs_rrs_8 = __BS(read_region_stream_8); /* write (single), stream */ t->bs_ws_1 = __BS(write_stream_1); t->bs_ws_2 = __BS(write_stream_2); t->bs_ws_4 = __BS(write_stream_4); t->bs_ws_8 = __BS(write_stream_8); /* write multiple, stream */ t->bs_wms_1 = __BS(write_multi_stream_1); t->bs_wms_2 = __BS(write_multi_stream_2); t->bs_wms_4 = __BS(write_multi_stream_4); t->bs_wms_8 = __BS(write_multi_stream_8); /* write region, stream */ t->bs_wrs_1 = __BS(write_region_stream_1); t->bs_wrs_2 = __BS(write_region_stream_2); t->bs_wrs_4 = __BS(write_region_stream_4); t->bs_wrs_8 = __BS(write_region_stream_8); #else /* CHIP_NEED_STREAM */ /* read (single), stream */ t->bs_rs_1 = __BS(read_1); t->bs_rs_2 = __BS(read_2); t->bs_rs_4 = __BS(read_4); t->bs_rs_8 = __BS(read_8); /* read multiple, stream */ t->bs_rms_1 = __BS(read_multi_1); t->bs_rms_2 = __BS(read_multi_2); t->bs_rms_4 = __BS(read_multi_4); t->bs_rms_8 = __BS(read_multi_8); /* read region, stream */ t->bs_rrs_1 = __BS(read_region_1); t->bs_rrs_2 = __BS(read_region_2); t->bs_rrs_4 = __BS(read_region_4); t->bs_rrs_8 = __BS(read_region_8); /* write (single), stream */ t->bs_ws_1 = __BS(write_1); t->bs_ws_2 = __BS(write_2); t->bs_ws_4 = __BS(write_4); t->bs_ws_8 = __BS(write_8); /* write multiple, stream */ t->bs_wms_1 = __BS(write_multi_1); t->bs_wms_2 = __BS(write_multi_2); t->bs_wms_4 = __BS(write_multi_4); t->bs_wms_8 = __BS(write_multi_8); /* write region, stream */ t->bs_wrs_1 = __BS(write_region_1); t->bs_wrs_2 = __BS(write_region_2); t->bs_wrs_4 = __BS(write_region_4); t->bs_wrs_8 = __BS(write_region_8); #endif /* CHIP_NEED_STREAM */ #ifdef CHIP_EXTENT /* XXX WE WANT EXTENT_NOCOALESCE, BUT WE CAN'T USE IT. XXX */ ex = extent_create(__S(__BS(bus)), 0x0UL, 0xffffffffUL, M_DEVBUF, (void *)CHIP_EX_STORE(v), CHIP_EX_STORE_SIZE(v), EX_NOWAIT); extent_alloc_region(ex, 0, 0xffffffffUL, EX_NOWAIT); #ifdef CHIP_W1_BUS_START /* * The window may be disabled. We notice this by seeing * -1 as the bus base address. */ if (CHIP_W1_BUS_START(v) == (bus_addr_t) -1) { #ifdef EXTENT_DEBUG printf("xxx: this space is disabled\n"); #endif return; } #ifdef EXTENT_DEBUG printf("xxx: freeing from 0x%x to 0x%x\n", CHIP_W1_BUS_START(v), CHIP_W1_BUS_END(v)); #endif extent_free(ex, CHIP_W1_BUS_START(v), CHIP_W1_BUS_END(v) - CHIP_W1_BUS_START(v) + 1, EX_NOWAIT); #endif #ifdef CHIP_W2_BUS_START if (CHIP_W2_BUS_START(v) != CHIP_W1_BUS_START(v)) { #ifdef EXTENT_DEBUG printf("xxx: freeing from 0x%lx to 0x%lx\n", (u_long)CHIP_W2_BUS_START(v), (u_long)CHIP_W2_BUS_END(v)); #endif extent_free(ex, CHIP_W2_BUS_START(v), CHIP_W2_BUS_END(v) - CHIP_W2_BUS_START(v) + 1, EX_NOWAIT); } else { #ifdef EXTENT_DEBUG printf("xxx: window 2 (0x%lx to 0x%lx) overlaps window 1\n", (u_long)CHIP_W2_BUS_START(v), (u_long)CHIP_W2_BUS_END(v)); #endif } #endif #ifdef CHIP_W3_BUS_START if (CHIP_W3_BUS_START(v) != CHIP_W1_BUS_START(v) && CHIP_W3_BUS_START(v) != CHIP_W2_BUS_START(v)) { #ifdef EXTENT_DEBUG printf("xxx: freeing from 0x%lx to 0x%lx\n", (u_long)CHIP_W3_BUS_START(v), (u_long)CHIP_W3_BUS_END(v)); #endif extent_free(ex, CHIP_W3_BUS_START(v), CHIP_W3_BUS_END(v) - CHIP_W3_BUS_START(v) + 1, EX_NOWAIT); } else { #ifdef EXTENT_DEBUG printf("xxx: window 2 (0x%lx to 0x%lx) overlaps window 1\n", (u_long)CHIP_W2_BUS_START(v), (u_long)CHIP_W2_BUS_END(v)); #endif } #endif #ifdef EXTENT_DEBUG extent_print(ex); #endif CHIP_EXTENT(v) = ex; #endif /* CHIP_EXTENT */ }
static int __BS(alloc)(void *v, bus_addr_t rstart, bus_addr_t rend, bus_size_t size, bus_size_t align, bus_size_t boundary, int flags, bus_addr_t *addrp, bus_space_handle_t *bshp) { #ifdef CHIP_EXTENT struct mips_bus_space_translation mbst; u_long addr; /* bogus but makes extent happy */ int error; #if CHIP_ALIGN_STRIDE != 0 int linear = flags & BUS_SPACE_MAP_LINEAR; /* * Can't map xxx space linearly. */ if (linear) return (EOPNOTSUPP); #endif /* * Do the requested allocation. */ #ifdef EXTENT_DEBUG printf("%s: allocating from %#"PRIxBUSADDR" to %#"PRIxBUSADDR"\n", __S(__BS(alloc)), rstart, rend); #endif error = extent_alloc_subregion(CHIP_EXTENT(v), rstart, rend, size, align, boundary, EX_FAST | EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0), &addr); if (error) { #ifdef EXTENT_DEBUG printf("%s: allocation failed (%d)\n", __S(__BS(alloc)), error); extent_print(CHIP_EXTENT(v)); #endif return (error); } #ifdef EXTENT_DEBUG printf("%s: allocated 0x%lx to %#"PRIxBUSSIZE"\n", __S(__BS(alloc)), addr, addr + size - 1); #endif error = __BS(translate)(v, addr, size, flags, &mbst); if (error) { (void) extent_free(CHIP_EXTENT(v), addr, size, EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0)); return (error); } *addrp = addr; #if !defined(__mips_o32) if (flags & BUS_SPACE_MAP_CACHEABLE) { *bshp = MIPS_PHYS_TO_XKPHYS_CACHED(mbst.mbst_sys_start + (addr - mbst.mbst_bus_start)); } else { *bshp = MIPS_PHYS_TO_XKPHYS_UNCACHED(mbst.mbst_sys_start + (addr - mbst.mbst_bus_start)); } #else if (flags & BUS_SPACE_MAP_CACHEABLE) { *bshp = MIPS_PHYS_TO_KSEG0(mbst.mbst_sys_start + (addr - mbst.mbst_bus_start)); } else *bshp = MIPS_PHYS_TO_KSEG1(mbst.mbst_sys_start + (addr - mbst.mbst_bus_start)); #endif return (0); #else /* ! CHIP_EXTENT */ return (EOPNOTSUPP); #endif /* CHIP_EXTENT */ }
static void __BS(unmap)(void *v, bus_space_handle_t h, bus_size_t size, int acct) { #if !defined(_LP64) || defined(CHIP_EXTENT) bus_addr_t addr = 0; /* initialize to appease gcc */ #endif #ifndef _LP64 bool handle_is_km; /* determine if h is addr obtained from uvm_km_alloc */ handle_is_km = !(MIPS_KSEG0_P(h) || MIPS_KSEG1_P(h)); #ifdef __mips_n32 if (handle_is_km == true) handle_is_km = !MIPS_XKPHYS_P(h); #endif if (handle_is_km == true) { paddr_t pa; vaddr_t va = (vaddr_t)trunc_page(h); vsize_t sz = (vsize_t)round_page((h % PAGE_SIZE) + size); int s; s = splhigh(); if (pmap_extract(pmap_kernel(), (vaddr_t)h, &pa) == false) panic("%s: pmap_extract failed", __func__); addr = (bus_addr_t)pa; #if 0 printf("%s:%d: addr %#"PRIxBUSADDR", sz %#"PRIxVSIZE"\n", __func__, __LINE__, addr, sz); #endif /* sanity check: this is why we couldn't map w/ kseg[0,1] */ KASSERT (((addr + sz) & ~MIPS_PHYS_MASK) != 0); pmap_kremove(va, sz); pmap_update(pmap_kernel()); uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); splx(s); } #endif /* _LP64 */ #ifdef CHIP_EXTENT if (acct == 0) return; #ifdef EXTENT_DEBUG printf("%s: freeing handle %#"PRIxBSH" for %#"PRIxBUSSIZE"\n", __S(__BS(unmap)), h, size); #endif #ifdef _LP64 KASSERT(MIPS_XKPHYS_P(h)); addr = MIPS_XKPHYS_TO_PHYS(h); #else if (handle_is_km == false) { if (MIPS_KSEG0_P(h)) addr = MIPS_KSEG0_TO_PHYS(h); #ifdef __mips_n32 else if (MIPS_XKPHYS_P(h)) addr = MIPS_XKPHYS_TO_PHYS(h); #endif else addr = MIPS_KSEG1_TO_PHYS(h); } #endif #ifdef CHIP_W1_BUS_START if (addr >= CHIP_W1_SYS_START(v) && addr <= CHIP_W1_SYS_END(v)) { addr = CHIP_W1_BUS_START(v) + (addr - CHIP_W1_SYS_START(v)); } else #endif #ifdef CHIP_W2_BUS_START if (addr >= CHIP_W2_SYS_START(v) && addr <= CHIP_W2_SYS_END(v)) { addr = CHIP_W2_BUS_START(v) + (addr - CHIP_W2_SYS_START(v)); } else #endif #ifdef CHIP_W3_BUS_START if (addr >= CHIP_W3_SYS_START(v) && addr <= CHIP_W3_SYS_END(v)) { addr = CHIP_W3_BUS_START(v) + (addr - CHIP_W3_SYS_START(v)); } else #endif { printf("\n"); #ifdef CHIP_W1_BUS_START printf("%s: sys window[1]=0x%lx-0x%lx\n", __S(__BS(unmap)), (u_long)CHIP_W1_SYS_START(v), (u_long)CHIP_W1_SYS_END(v)); #endif #ifdef CHIP_W2_BUS_START printf("%s: sys window[2]=0x%lx-0x%lx\n", __S(__BS(unmap)), (u_long)CHIP_W2_SYS_START(v), (u_long)CHIP_W2_SYS_END(v)); #endif #ifdef CHIP_W3_BUS_START printf("%s: sys window[3]=0x%lx-0x%lx\n", __S(__BS(unmap)), (u_long)CHIP_W3_SYS_START(v), (u_long)CHIP_W3_SYS_END(v)); #endif panic("%s: don't know how to unmap %#"PRIxBSH, __S(__BS(unmap)), h); } #ifdef EXTENT_DEBUG printf("%s: freeing %#"PRIxBUSADDR" to %#"PRIxBUSADDR"\n", __S(__BS(unmap)), addr, addr + size - 1); #endif int error = extent_free(CHIP_EXTENT(v), addr, size, EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0)); if (error) { printf("%s: WARNING: could not unmap" " %#"PRIxBUSADDR"-%#"PRIxBUSADDR" (error %d)\n", __S(__BS(unmap)), addr, addr + size - 1, error); #ifdef EXTENT_DEBUG extent_print(CHIP_EXTENT(v)); #endif } #endif /* CHIP_EXTENT */ #if !defined(_LP64) || defined(CHIP_EXTENT) __USE(addr); #endif }
static int __BS(map)(void *v, bus_addr_t addr, bus_size_t size, int flags, bus_space_handle_t *hp, int acct) { struct mips_bus_space_translation mbst; int error; /* * Get the translation for this address. */ error = __BS(translate)(v, addr, size, flags, &mbst); if (error) return (error); #ifdef CHIP_EXTENT if (acct == 0) goto mapit; #ifdef EXTENT_DEBUG printf("%s: allocating %#"PRIxBUSADDR" to %#"PRIxBUSADDR"\n", __S(__BS(map)), addr, addr + size - 1); #endif error = extent_alloc_region(CHIP_EXTENT(v), addr, size, EX_NOWAIT | (CHIP_EX_MALLOC_SAFE(v) ? EX_MALLOCOK : 0)); if (error) { #ifdef EXTENT_DEBUG printf("%s: allocation failed (%d)\n", __S(__BS(map)), error); extent_print(CHIP_EXTENT(v)); #endif return (error); } mapit: #endif /* CHIP_EXTENT */ addr = mbst.mbst_sys_start + (addr - mbst.mbst_bus_start); #if defined(__mips_n32) || defined(_LP64) if (flags & BUS_SPACE_MAP_CACHEABLE) { #ifdef __mips_n32 if (((addr + size) & ~MIPS_PHYS_MASK) == 0) *hp = (intptr_t)MIPS_PHYS_TO_KSEG0(addr); else #endif *hp = MIPS_PHYS_TO_XKPHYS_CACHED(addr); } else if (flags & BUS_SPACE_MAP_PREFETCHABLE) { *hp = MIPS_PHYS_TO_XKPHYS_ACC(addr); } else { #ifdef __mips_n32 if (((addr + size) & ~MIPS_PHYS_MASK) == 0) *hp = (intptr_t)MIPS_PHYS_TO_KSEG1(addr); else #endif *hp = MIPS_PHYS_TO_XKPHYS_UNCACHED(addr); } #else if (((addr + size) & ~MIPS_PHYS_MASK) != 0) { vaddr_t va; paddr_t pa; int s; size = round_page((addr % PAGE_SIZE) + size); va = uvm_km_alloc(kernel_map, size, PAGE_SIZE, UVM_KMF_VAONLY | UVM_KMF_NOWAIT); if (va == 0) return ENOMEM; /* check use of handle_is_km in BS(unmap) */ KASSERT(!(MIPS_KSEG0_P(va) || MIPS_KSEG1_P(va))); *hp = va + (addr & PAGE_MASK); pa = trunc_page(addr); s = splhigh(); while (size != 0) { pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0); pa += PAGE_SIZE; va += PAGE_SIZE; size -= PAGE_SIZE; } pmap_update(pmap_kernel()); splx(s); } else { if (flags & BUS_SPACE_MAP_CACHEABLE) *hp = (intptr_t)MIPS_PHYS_TO_KSEG0(addr); else *hp = (intptr_t)MIPS_PHYS_TO_KSEG1(addr); } #endif return (0); }