Lines Matching refs:gru

84 static int gru_wrap_asid(struct gru_state *gru)  in gru_wrap_asid()  argument
86 gru_dbg(grudev, "gid %d\n", gru->gs_gid); in gru_wrap_asid()
88 gru->gs_asid_gen++; in gru_wrap_asid()
93 static int gru_reset_asid_limit(struct gru_state *gru, int asid) in gru_reset_asid_limit() argument
97 gru_dbg(grudev, "gid %d, asid 0x%x\n", gru->gs_gid, asid); in gru_reset_asid_limit()
101 asid = gru_wrap_asid(gru); in gru_reset_asid_limit()
102 gru_flush_all_tlb(gru); in gru_reset_asid_limit()
103 gid = gru->gs_gid; in gru_reset_asid_limit()
106 if (!gru->gs_gts[i] || is_kernel_context(gru->gs_gts[i])) in gru_reset_asid_limit()
108 inuse_asid = gru->gs_gts[i]->ts_gms->ms_asids[gid].mt_asid; in gru_reset_asid_limit()
110 gru->gs_gid, gru->gs_gts[i], gru->gs_gts[i]->ts_gms, in gru_reset_asid_limit()
121 asid = gru_wrap_asid(gru); in gru_reset_asid_limit()
129 gru->gs_asid_limit = limit; in gru_reset_asid_limit()
130 gru->gs_asid = asid; in gru_reset_asid_limit()
131 gru_dbg(grudev, "gid %d, new asid 0x%x, new_limit 0x%x\n", gru->gs_gid, in gru_reset_asid_limit()
137 static int gru_assign_asid(struct gru_state *gru) in gru_assign_asid() argument
141 gru->gs_asid += ASID_INC; in gru_assign_asid()
142 asid = gru->gs_asid; in gru_assign_asid()
143 if (asid >= gru->gs_asid_limit) in gru_assign_asid()
144 asid = gru_reset_asid_limit(gru, asid); in gru_assign_asid()
146 gru_dbg(grudev, "gid %d, asid 0x%x\n", gru->gs_gid, asid); in gru_assign_asid()
172 unsigned long gru_reserve_cb_resources(struct gru_state *gru, int cbr_au_count, in gru_reserve_cb_resources() argument
175 return reserve_resources(&gru->gs_cbr_map, cbr_au_count, GRU_CBR_AU, in gru_reserve_cb_resources()
179 unsigned long gru_reserve_ds_resources(struct gru_state *gru, int dsr_au_count, in gru_reserve_ds_resources() argument
182 return reserve_resources(&gru->gs_dsr_map, dsr_au_count, GRU_DSR_AU, in gru_reserve_ds_resources()
186 static void reserve_gru_resources(struct gru_state *gru, in reserve_gru_resources() argument
189 gru->gs_active_contexts++; in reserve_gru_resources()
191 gru_reserve_cb_resources(gru, gts->ts_cbr_au_count, in reserve_gru_resources()
194 gru_reserve_ds_resources(gru, gts->ts_dsr_au_count, NULL); in reserve_gru_resources()
197 static void free_gru_resources(struct gru_state *gru, in free_gru_resources() argument
200 gru->gs_active_contexts--; in free_gru_resources()
201 gru->gs_cbr_map |= gts->ts_cbr_map; in free_gru_resources()
202 gru->gs_dsr_map |= gts->ts_dsr_map; in free_gru_resources()
212 static int check_gru_resources(struct gru_state *gru, int cbr_au_count, in check_gru_resources() argument
215 return hweight64(gru->gs_cbr_map) >= cbr_au_count in check_gru_resources()
216 && hweight64(gru->gs_dsr_map) >= dsr_au_count in check_gru_resources()
217 && gru->gs_active_contexts < max_active_contexts; in check_gru_resources()
224 static int gru_load_mm_tracker(struct gru_state *gru, in gru_load_mm_tracker() argument
228 struct gru_mm_tracker *asids = &gms->ms_asids[gru->gs_gid]; in gru_load_mm_tracker()
235 spin_lock(&gru->gs_asid_lock); in gru_load_mm_tracker()
237 gru->gs_asid_gen)) { in gru_load_mm_tracker()
238 asid = gru_assign_asid(gru); in gru_load_mm_tracker()
240 asids->mt_asid_gen = gru->gs_asid_gen; in gru_load_mm_tracker()
245 spin_unlock(&gru->gs_asid_lock); in gru_load_mm_tracker()
249 if (!test_bit(gru->gs_gid, gms->ms_asidmap)) in gru_load_mm_tracker()
250 __set_bit(gru->gs_gid, gms->ms_asidmap); in gru_load_mm_tracker()
255 gru->gs_gid, gts, gms, gts->ts_ctxnum, asid, in gru_load_mm_tracker()
260 static void gru_unload_mm_tracker(struct gru_state *gru, in gru_unload_mm_tracker() argument
267 asids = &gms->ms_asids[gru->gs_gid]; in gru_unload_mm_tracker()
270 spin_lock(&gru->gs_asid_lock); in gru_unload_mm_tracker()
274 gru->gs_gid, gts, gms, gts->ts_ctxnum, gms->ms_asidmap[0]); in gru_unload_mm_tracker()
275 spin_unlock(&gru->gs_asid_lock); in gru_unload_mm_tracker()
426 struct gru_state *gru; in gru_free_gru_context() local
428 gru = gts->ts_gru; in gru_free_gru_context()
429 gru_dbg(grudev, "gts %p, gid %d\n", gts, gru->gs_gid); in gru_free_gru_context()
431 spin_lock(&gru->gs_lock); in gru_free_gru_context()
432 gru->gs_gts[gts->ts_ctxnum] = NULL; in gru_free_gru_context()
433 free_gru_resources(gru, gts); in gru_free_gru_context()
434 BUG_ON(test_bit(gts->ts_ctxnum, &gru->gs_context_map) == 0); in gru_free_gru_context()
435 __clear_bit(gts->ts_ctxnum, &gru->gs_context_map); in gru_free_gru_context()
439 spin_unlock(&gru->gs_lock); in gru_free_gru_context()
544 struct gru_state *gru = gts->ts_gru; in gru_unload_context() local
550 cch = get_cch(gru->gs_gru_base_vaddr, ctxnum); in gru_unload_context()
559 gru_unload_mm_tracker(gru, gts); in gru_unload_context()
561 gru_unload_context_data(gts->ts_gdata, gru->gs_gru_base_vaddr, in gru_unload_context()
580 struct gru_state *gru = gts->ts_gru; in gru_load_context() local
584 cch = get_cch(gru->gs_gru_base_vaddr, ctxnum); in gru_load_context()
613 asid = gru_load_mm_tracker(gru, gts); in gru_load_context()
628 gru_load_context_data(gts->ts_gdata, gru->gs_gru_base_vaddr, ctxnum, in gru_load_context()
648 struct gru_state *gru = gts->ts_gru; in gru_update_cch() local
651 cch = get_cch(gru->gs_gru_base_vaddr, ctxnum); in gru_update_cch()
655 if (gru->gs_gts[gts->ts_ctxnum] != gts) in gru_update_cch()
699 static int gru_check_chiplet_assignment(struct gru_state *gru, in gru_check_chiplet_assignment() argument
710 return gru->gs_blade_id == blade_id && in gru_check_chiplet_assignment()
711 (chiplet_id < 0 || chiplet_id == gru->gs_chiplet_id); in gru_check_chiplet_assignment()
721 struct gru_state *gru; in gru_check_context_placement() local
729 gru = gts->ts_gru; in gru_check_context_placement()
736 if (!gru || gts->ts_tgid_owner != current->tgid) in gru_check_context_placement()
739 if (!gru_check_chiplet_assignment(gru, gts)) { in gru_check_context_placement()
782 struct gru_state *gru, *gru0; in gru_steal_context() local
797 gru = blade->bs_lru_gru; in gru_steal_context()
799 gru = next_gru(blade, gru); in gru_steal_context()
800 blade->bs_lru_gru = gru; in gru_steal_context()
803 gru0 = gru; in gru_steal_context()
805 if (gru_check_chiplet_assignment(gru, gts)) { in gru_steal_context()
806 if (check_gru_resources(gru, cbr, dsr, GRU_NUM_CCH)) in gru_steal_context()
808 spin_lock(&gru->gs_lock); in gru_steal_context()
810 if (flag && gru == gru0 && ctxnum == ctxnum0) in gru_steal_context()
812 ngts = gru->gs_gts[ctxnum]; in gru_steal_context()
823 spin_unlock(&gru->gs_lock); in gru_steal_context()
824 if (ngts || (flag && gru == gru0 && ctxnum == ctxnum0)) in gru_steal_context()
827 if (flag && gru == gru0) in gru_steal_context()
831 gru = next_gru(blade, gru); in gru_steal_context()
846 gru->gs_gid, ctxnum, ngts, cbr, dsr, hweight64(gru->gs_cbr_map), in gru_steal_context()
847 hweight64(gru->gs_dsr_map)); in gru_steal_context()
853 static int gru_assign_context_number(struct gru_state *gru) in gru_assign_context_number() argument
857 ctxnum = find_first_zero_bit(&gru->gs_context_map, GRU_NUM_CCH); in gru_assign_context_number()
858 __set_bit(ctxnum, &gru->gs_context_map); in gru_assign_context_number()
867 struct gru_state *gru, *grux; in gru_assign_gru_context() local
874 gru = NULL; in gru_assign_gru_context()
882 gru = grux; in gru_assign_gru_context()
889 if (gru) { in gru_assign_gru_context()
890 spin_lock(&gru->gs_lock); in gru_assign_gru_context()
891 if (!check_gru_resources(gru, gts->ts_cbr_au_count, in gru_assign_gru_context()
893 spin_unlock(&gru->gs_lock); in gru_assign_gru_context()
896 reserve_gru_resources(gru, gts); in gru_assign_gru_context()
897 gts->ts_gru = gru; in gru_assign_gru_context()
898 gts->ts_blade = gru->gs_blade_id; in gru_assign_gru_context()
899 gts->ts_ctxnum = gru_assign_context_number(gru); in gru_assign_gru_context()
901 gru->gs_gts[gts->ts_ctxnum] = gts; in gru_assign_gru_context()
902 spin_unlock(&gru->gs_lock); in gru_assign_gru_context()
915 return gru; in gru_assign_gru_context()