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

Function mtk_pci_attach

freebsd/mips/mediatek/mtk_pcie.c:228–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228static int
229mtk_pci_attach(device_t dev)
230{
231 struct mtk_pci_softc *sc = device_get_softc(dev);
232 struct mtk_pci_range io_space, mem_space;
233 phandle_t node;
234 intptr_t xref;
235 int i, rid;
236
237 sc->sc_dev = dev;
238 mt_sc = sc;
239 sc->addr_mask = 0xffffffff;
240
241 /* Request our memory */
242 rid = 0;
243 sc->pci_res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
244 RF_ACTIVE);
245 if (sc->pci_res[0] == NULL) {
246 device_printf(dev, "could not allocate memory resource\n");
247 return (ENXIO);
248 }
249
250 /* See how many interrupts we need */
251 if (sc->socid == MTK_SOC_MT7621)
252 sc->sc_num_irq = 3;
253 else {
254 sc->sc_num_irq = 1;
255 sc->pci_res[2] = sc->pci_res[3] = NULL;
256 sc->pci_intrhand[1] = sc->pci_intrhand[2] = NULL;
257 }
258
259 /* Request our interrupts */
260 for (i = 1; i <= sc->sc_num_irq ; i++) {
261 rid = i - 1;
262 sc->pci_res[i] = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
263 RF_ACTIVE);
264 if (sc->pci_res[i] == NULL) {
265 device_printf(dev, "could not allocate interrupt "
266 "resource %d\n", rid);
267 goto cleanup_res;
268 }
269 }
270
271 /* Parse our PCI 'ranges' property */
272 node = ofw_bus_get_node(dev);
273 xref = OF_xref_from_node(node);
274 if (mtk_pci_ranges(node, &io_space, &mem_space)) {
275 device_printf(dev, "could not retrieve 'ranges' data\n");
276 goto cleanup_res;
277 }
278
279 /* Memory, I/O and IRQ resource limits */
280 sc->sc_io_base = io_space.base;
281 sc->sc_io_size = io_space.len;
282 sc->sc_mem_base = mem_space.base;
283 sc->sc_mem_size = mem_space.len;
284 sc->sc_irq_start = MTK_PCIE0_IRQ;
285 sc->sc_irq_end = MTK_PCIE2_IRQ;

Callers

nothing calls this directly

Calls 15

device_get_softcFunction · 0.85
bus_alloc_resource_anyFunction · 0.85
device_printfFunction · 0.85
mtk_pci_rangesFunction · 0.85
rman_initFunction · 0.85
rman_manage_regionFunction · 0.85
mtk_pcie_phy_initFunction · 0.85
intr_pic_registerFunction · 0.85
bus_setup_intrFunction · 0.85
device_add_childFunction · 0.85
bus_generic_attachFunction · 0.85
bus_teardown_intrFunction · 0.85

Tested by

no test coverage detected