2 * The PCI Library -- NetBSD libpci access
3 * (based on FreeBSD /dev/pci access)
5 * Copyright (c) 1999 Jari Kirma <kirma@cs.hut.fi>
6 * Copyright (c) 2002 Quentin Garnier <cube@cubidou.net>
8 * Can be freely distributed and used under the terms of the GNU GPL.
12 * Read functionality of this driver is briefly tested, and seems
13 * to supply basic information correctly, but I promise no more.
25 nbsd_config(struct pci_access
*a
)
27 a
->method_params
[PCI_ACCESS_NBSD_LIBPCI
] = PATH_NBSD_DEVICE
;
31 nbsd_detect(struct pci_access
*a
)
33 char *name
= a
->method_params
[PCI_ACCESS_NBSD_LIBPCI
];
35 if (access(name
, R_OK
))
37 a
->warning("Cannot open %s", name
);
40 a
->debug("...using %s", name
);
45 nbsd_init(struct pci_access
*a
)
47 char *name
= a
->method_params
[PCI_ACCESS_NBSD_LIBPCI
];
49 a
->fd
= open(name
, O_RDWR
, 0);
52 a
->error("nbsd_init: %s open failed", name
);
57 nbsd_cleanup(struct pci_access
*a
)
63 nbsd_read(struct pci_dev
*d
, int pos
, byte
*buf
, int len
)
67 if (!(len
== 1 || len
== 2 || len
== 4))
69 return pci_generic_block_read(d
, pos
, buf
, len
);
73 if (pcibus_conf_read(d
->access
->fd
, d
->bus
, d
->dev
, d
->func
, pos
, &val
) < 0)
74 d
->access
->error("nbsd_read: pci_bus_conf_read() failed");
79 buf
[0] = (u8
) ((val
>>16) & 0xff);
82 ((u16
*) buf
)[0] = (u16
) val
;
85 ((u32
*) buf
)[0] = (u32
) val
;
92 nbsd_write(struct pci_dev
*d
, int pos
, byte
*buf
, int len
)
96 if (!(len
== 1 || len
== 2 || len
== 4))
98 return pci_generic_block_write(d
, pos
, buf
, len
);
107 val
= ((u16
*) buf
)[0];
110 val
= ((u32
*) buf
)[0];
114 if (pcibus_conf_write(d
->access
->fd
, d
->bus
, d
->dev
, d
->func
, pos
, val
) < 0)
115 d
->access
->error("nbsd_write: pci_bus_conf_write() failed");
120 struct pci_methods pm_nbsd_libpci
= {
127 pci_generic_fill_info
,
131 NULL
/* dev_cleanup */