Deleted Added
full compact
fwohci_pci.c (271795) fwohci_pci.c (272214)
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 19 unchanged lines hidden (view full) ---

28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/dev/firewire/fwohci_pci.c 271795 2014-09-18 17:28:21Z will $");
36__FBSDID("$FreeBSD: head/sys/dev/firewire/fwohci_pci.c 272214 2014-09-27 16:50:21Z kan $");
37
38#define BOUNCE_BUFFER_TEST 0
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/module.h>
44#include <sys/bus.h>

--- 17 unchanged lines hidden (view full) ---

62
63static int fwohci_pci_attach(device_t self);
64static int fwohci_pci_detach(device_t self);
65
66/*
67 * The probe routine.
68 */
69static int
37
38#define BOUNCE_BUFFER_TEST 0
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/module.h>
44#include <sys/bus.h>

--- 17 unchanged lines hidden (view full) ---

62
63static int fwohci_pci_attach(device_t self);
64static int fwohci_pci_detach(device_t self);
65
66/*
67 * The probe routine.
68 */
69static int
70fwohci_pci_probe( device_t dev )
70fwohci_pci_probe(device_t dev)
71{
72 uint32_t id;
73
74 id = pci_get_devid(dev);
75 if (id == (FW_VENDORID_NATSEMI | FW_DEVICE_CS4210)) {
76 device_set_desc(dev, "National Semiconductor CS4210");
77 return BUS_PROBE_DEFAULT;
78 }

--- 127 unchanged lines hidden (view full) ---

206fwohci_pci_init(device_t self)
207{
208 int olatency, latency, ocache_line, cache_line;
209 uint16_t cmd;
210
211 cmd = pci_read_config(self, PCIR_COMMAND, 2);
212 cmd |= PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN;
213#if 1 /* for broken hardware */
71{
72 uint32_t id;
73
74 id = pci_get_devid(dev);
75 if (id == (FW_VENDORID_NATSEMI | FW_DEVICE_CS4210)) {
76 device_set_desc(dev, "National Semiconductor CS4210");
77 return BUS_PROBE_DEFAULT;
78 }

--- 127 unchanged lines hidden (view full) ---

206fwohci_pci_init(device_t self)
207{
208 int olatency, latency, ocache_line, cache_line;
209 uint16_t cmd;
210
211 cmd = pci_read_config(self, PCIR_COMMAND, 2);
212 cmd |= PCIM_CMD_BUSMASTEREN | PCIM_CMD_MWRICEN;
213#if 1 /* for broken hardware */
214 cmd &= ~PCIM_CMD_MWRICEN;
214 cmd &= ~PCIM_CMD_MWRICEN;
215#endif
216 pci_write_config(self, PCIR_COMMAND, cmd, 2);
217
218 /*
219 * Some Sun PCIO-2 FireWire controllers have their intpin register
220 * bogusly set to 0, although it should be 3. Correct that.
221 */
222 if (pci_get_devid(self) == (FW_VENDORID_SUN | FW_DEVICE_PCIO2FW) &&

--- 83 unchanged lines hidden (view full) ---

306 /*maxsize*/0x100000,
307 /*nsegments*/0x20,
308 /*maxsegsz*/0x8000,
309 /*flags*/BUS_DMA_ALLOCNOW,
310 /*lockfunc*/busdma_lock_mutex,
311 /*lockarg*/FW_GMTX(&sc->fc),
312 &sc->fc.dmat);
313 if (err != 0) {
215#endif
216 pci_write_config(self, PCIR_COMMAND, cmd, 2);
217
218 /*
219 * Some Sun PCIO-2 FireWire controllers have their intpin register
220 * bogusly set to 0, although it should be 3. Correct that.
221 */
222 if (pci_get_devid(self) == (FW_VENDORID_SUN | FW_DEVICE_PCIO2FW) &&

--- 83 unchanged lines hidden (view full) ---

306 /*maxsize*/0x100000,
307 /*nsegments*/0x20,
308 /*maxsegsz*/0x8000,
309 /*flags*/BUS_DMA_ALLOCNOW,
310 /*lockfunc*/busdma_lock_mutex,
311 /*lockarg*/FW_GMTX(&sc->fc),
312 &sc->fc.dmat);
313 if (err != 0) {
314 printf("fwohci_pci_attach: Could not allocate DMA tag "
315 "- error %d\n", err);
316 return (ENOMEM);
314 device_printf(self, "fwohci_pci_attach: Could not allocate DMA "
315 "tag - error %d\n", err);
316 fwohci_pci_detach(self);
317 return (ENOMEM);
317 }
318
319 err = fwohci_init(sc, self);
320
318 }
319
320 err = fwohci_init(sc, self);
321
321 if (err) {
322 if (err != 0) {
322 device_printf(self, "fwohci_init failed with err=%d\n", err);
323 fwohci_pci_detach(self);
324 return EIO;
325 }
326
327 /* probe and attach a child device(firewire) */
328 bus_generic_probe(self);
329 bus_generic_attach(self);
330
331 return 0;
332}
333
334static int
335fwohci_pci_detach(device_t self)
336{
337 fwohci_softc_t *sc = device_get_softc(self);
338 int s;
339
323 device_printf(self, "fwohci_init failed with err=%d\n", err);
324 fwohci_pci_detach(self);
325 return EIO;
326 }
327
328 /* probe and attach a child device(firewire) */
329 bus_generic_probe(self);
330 bus_generic_attach(self);
331
332 return 0;
333}
334
335static int
336fwohci_pci_detach(device_t self)
337{
338 fwohci_softc_t *sc = device_get_softc(self);
339 int s;
340
340
341 s = splfw();
342
343 if (sc->bsr)
344 fwohci_stop(sc, self);
345
346 bus_generic_detach(self);
341 s = splfw();
342
343 if (sc->bsr)
344 fwohci_stop(sc, self);
345
346 bus_generic_detach(self);
347
347 if (sc->fc.bdev) {
348 device_delete_child(self, sc->fc.bdev);
349 sc->fc.bdev = NULL;
350 }
351
352 /* disable interrupts that might have been switched on */
353 if (sc->bst && sc->bsh)
354 bus_space_write_4(sc->bst, sc->bsh,

--- 8 unchanged lines hidden (view full) ---

363 "Could not tear down irq, %d\n", err);
364 sc->ih = NULL;
365 }
366 bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
367 sc->irq_res = NULL;
368 }
369
370 if (sc->bsr) {
348 if (sc->fc.bdev) {
349 device_delete_child(self, sc->fc.bdev);
350 sc->fc.bdev = NULL;
351 }
352
353 /* disable interrupts that might have been switched on */
354 if (sc->bst && sc->bsh)
355 bus_space_write_4(sc->bst, sc->bsh,

--- 8 unchanged lines hidden (view full) ---

364 "Could not tear down irq, %d\n", err);
365 sc->ih = NULL;
366 }
367 bus_release_resource(self, SYS_RES_IRQ, 0, sc->irq_res);
368 sc->irq_res = NULL;
369 }
370
371 if (sc->bsr) {
371 bus_release_resource(self, SYS_RES_MEMORY,PCI_CBMEM,sc->bsr);
372 bus_release_resource(self, SYS_RES_MEMORY, PCI_CBMEM, sc->bsr);
372 sc->bsr = NULL;
373 sc->bst = 0;
374 sc->bsh = 0;
375 }
376
377 fwohci_detach(sc, self);
378 mtx_destroy(FW_GMTX(&sc->fc));
379 splx(s);

--- 43 unchanged lines hidden (view full) ---

423 int err = 0;
424
425 sc = (struct fwohci_softc *)device_get_softc(dev);
426 child = device_add_child(dev, name, unit);
427 if (child == NULL)
428 return (child);
429
430 sc->fc.bdev = child;
373 sc->bsr = NULL;
374 sc->bst = 0;
375 sc->bsh = 0;
376 }
377
378 fwohci_detach(sc, self);
379 mtx_destroy(FW_GMTX(&sc->fc));
380 splx(s);

--- 43 unchanged lines hidden (view full) ---

424 int err = 0;
425
426 sc = (struct fwohci_softc *)device_get_softc(dev);
427 child = device_add_child(dev, name, unit);
428 if (child == NULL)
429 return (child);
430
431 sc->fc.bdev = child;
431 device_set_ivars(child, (void *)&sc->fc);
432 device_set_ivars(child, &sc->fc);
432
433 err = device_probe_and_attach(child);
434 if (err) {
435 device_printf(dev, "probe_and_attach failed with err=%d\n",
436 err);
437 fwohci_pci_detach(dev);
438 device_delete_child(dev, child);
439 return NULL;
440 }
441
442 /* XXX
443 * Clear the bus reset event flag to start transactions even when
444 * interrupt is disabled during the boot process.
445 */
446 if (cold) {
447 int s;
448 DELAY(250); /* 2 cycles */
449 s = splfw();
433
434 err = device_probe_and_attach(child);
435 if (err) {
436 device_printf(dev, "probe_and_attach failed with err=%d\n",
437 err);
438 fwohci_pci_detach(dev);
439 device_delete_child(dev, child);
440 return NULL;
441 }
442
443 /* XXX
444 * Clear the bus reset event flag to start transactions even when
445 * interrupt is disabled during the boot process.
446 */
447 if (cold) {
448 int s;
449 DELAY(250); /* 2 cycles */
450 s = splfw();
450 fwohci_poll((void *)sc, 0, -1);
451 fwohci_poll(&sc->fc, 0, -1);
451 splx(s);
452 }
453
454 return (child);
455}
456
457static device_method_t fwohci_methods[] = {
458 /* Device interface */

--- 25 unchanged lines hidden ---
452 splx(s);
453 }
454
455 return (child);
456}
457
458static device_method_t fwohci_methods[] = {
459 /* Device interface */

--- 25 unchanged lines hidden ---