MCPcopy Create free account
hub / github.com/F-Stack/f-stack / beripic_attach

Function beripic_attach

freebsd/mips/beri/beri_pic.c:170–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170static int
171beripic_attach(device_t dev)
172{
173 struct beripic_softc *sc;
174 struct beri_pic_isrc *pic_isrc;
175 const char *name;
176 struct intr_irqsrc *isrc;
177 intptr_t xref;
178 uint32_t unit;
179 int err;
180 int i;
181
182 sc = device_get_softc(dev);
183 sc->dev = dev;
184
185 if (bus_alloc_resources(dev, beri_pic_spec, sc->res)) {
186 device_printf(dev, "could not allocate resources\n");
187 return (ENXIO);
188 }
189
190 xref = OF_xref_from_node(ofw_bus_get_node(dev));
191 name = device_get_nameunit(dev);
192 unit = device_get_unit(dev);
193 sc->nirqs = BP_NUM_IRQS;
194
195 for (i = 0; i < sc->nirqs; i++) {
196 sc->irqs[i].irq = i;
197 isrc = &sc->irqs[i].isrc;
198
199 /* Assign mips hard irq number. */
200 pic_isrc = (struct beri_pic_isrc *)isrc;
201 pic_isrc->mips_hard_irq = sc->mips_hard_irq_idx++;
202 /* Last IRQ is used for IPIs. */
203 if (sc->mips_hard_irq_idx >= (BP_NUM_HARD_IRQS - 1)) {
204 sc->mips_hard_irq_idx = 0;
205 }
206
207 err = intr_isrc_register(isrc, sc->dev,
208 0, "pic%d,%d", unit, i);
209 bus_write_8(sc->res[BP_CFG], i * 8, 0);
210 }
211
212 /*
213 * Now, when everything is initialized, it's right time to
214 * register interrupt controller to interrupt framefork.
215 */
216 if (intr_pic_register(dev, xref) == NULL) {
217 device_printf(dev, "could not register PIC\n");
218 return (ENXIO);
219 }
220
221 /* Last IRQ is used for IPIs. */
222 for (i = 0; i < (BP_NUM_HARD_IRQS - 1); i++) {
223 sc->hirq[i].sc = sc;
224 sc->hirq[i].irq = i;
225 if (bus_setup_intr(dev, sc->res[4+i], INTR_TYPE_CLK,
226 beri_pic_intr, NULL, &sc->hirq[i], sc->ih[i])) {
227 device_printf(dev, "could not setup irq handler\n");

Callers

nothing calls this directly

Calls 9

device_get_softcFunction · 0.85
bus_alloc_resourcesFunction · 0.85
device_printfFunction · 0.85
device_get_nameunitFunction · 0.85
device_get_unitFunction · 0.85
intr_isrc_registerFunction · 0.85
intr_pic_registerFunction · 0.85
bus_setup_intrFunction · 0.85
intr_pic_deregisterFunction · 0.85

Tested by

no test coverage detected