uprintf is really really dangerous to use in drivers. This example
driver only works if you compile it as a module because uprintf panics the system if there's no controlling terminal (at least in some versions of FreeBSD). Also, make things a little more style(9)ish.
This commit is contained in:
parent
d87561578e
commit
d615529c6b
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=19259
1 changed files with 19 additions and 24 deletions
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/systm.h> /* uprintf */
|
||||
#include <sys/systm.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/param.h> /* defines used in kernel.h */
|
||||
#include <sys/kernel.h> /* types used in module initialization */
|
||||
|
@ -65,7 +65,7 @@ mypci_open(dev_t dev, int oflags, int devtype, struct proc *p)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
uprintf("Opened device \"mypci\" successfully.\n");
|
||||
printf("Opened device \"mypci\" successfully.\n");
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ mypci_close(dev_t dev, int fflag, int devtype, struct proc *p)
|
|||
{
|
||||
int err=0;
|
||||
|
||||
uprintf("Closing device \"mypci.\"\n");
|
||||
printf("Closing device \"mypci.\"\n");
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ mypci_read(dev_t dev, struct uio *uio, int ioflag)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
uprintf("mypci read!\n");
|
||||
printf("mypci read!\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ mypci_write(dev_t dev, struct uio *uio, int ioflag)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
uprintf("mypci write!\n");
|
||||
printf("mypci write!\n");
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
@ -104,12 +104,11 @@ mypci_write(dev_t dev, struct uio *uio, int ioflag)
|
|||
static int
|
||||
mypci_probe(device_t dev)
|
||||
{
|
||||
uprintf("MyPCI Probe\n"
|
||||
"Vendor ID : 0x%x\n"
|
||||
"Device ID : 0x%x\n",pci_get_vendor(dev),pci_get_device(dev));
|
||||
device_printf(dev, "MyPCI Probe\nVendor ID : 0x%x\nDevice ID : 0x%x\n",
|
||||
pci_get_vendor(dev), pci_get_device(dev));
|
||||
|
||||
if (pci_get_vendor(dev) == 0x11c1) {
|
||||
uprintf("We've got the Winmodem, probe successful!\n");
|
||||
printf("We've got the Winmodem, probe successful!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -121,14 +120,10 @@ mypci_probe(device_t dev)
|
|||
static int
|
||||
mypci_attach(device_t dev)
|
||||
{
|
||||
uprintf("MyPCI Attach for : deviceID : 0x%x\n",pci_get_vendor(dev));
|
||||
sdev = make_dev(<literal>&</literal>mypci_cdevsw,
|
||||
0,
|
||||
UID_ROOT,
|
||||
GID_WHEEL,
|
||||
0600,
|
||||
"mypci");
|
||||
uprintf("Mypci device loaded.\n");
|
||||
printf("MyPCI Attach for : deviceID : 0x%x\n",pci_get_vendor(dev));
|
||||
sdev = make_dev(<literal>&</literal>mypci_cdevsw, 0, UID_ROOT, GID_WHEEL,
|
||||
0600, "mypci");
|
||||
printf("Mypci device loaded.\n");
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
|
@ -137,7 +132,7 @@ mypci_attach(device_t dev)
|
|||
static int
|
||||
mypci_detach(device_t dev)
|
||||
{
|
||||
uprintf("Mypci detach!\n");
|
||||
printf("Mypci detach!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -146,7 +141,7 @@ mypci_detach(device_t dev)
|
|||
static int
|
||||
mypci_shutdown(device_t dev)
|
||||
{
|
||||
uprintf("Mypci shutdown!\n");
|
||||
printf("Mypci shutdown!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -156,7 +151,7 @@ mypci_shutdown(device_t dev)
|
|||
static int
|
||||
mypci_suspend(device_t dev)
|
||||
{
|
||||
uprintf("Mypci suspend!\n");
|
||||
printf("Mypci suspend!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -167,7 +162,7 @@ mypci_suspend(device_t dev)
|
|||
static int
|
||||
mypci_resume(device_t dev)
|
||||
{
|
||||
uprintf("Mypci resume!\n");
|
||||
printf("Mypci resume!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -231,7 +226,7 @@ DRIVER_MODULE(mypci, pci, mypci_driver, mypci_devclass, 0, 0);</programlisting>
|
|||
sc->bar0res = bus_alloc_resource(dev, SYS_RES_MEMORY, &(sc->bar0id),
|
||||
0, ~0, 1, RF_ACTIVE);
|
||||
if (sc->bar0res == NULL) {
|
||||
uprintf("Memory allocation of PCI base register 0 failed!\n");
|
||||
printf("Memory allocation of PCI base register 0 failed!\n");
|
||||
error = ENXIO;
|
||||
goto fail1;
|
||||
}
|
||||
|
@ -240,7 +235,7 @@ DRIVER_MODULE(mypci, pci, mypci_driver, mypci_devclass, 0, 0);</programlisting>
|
|||
sc->bar1res = bus_alloc_resource(dev, SYS_RES_MEMORY, &(sc->bar1id),
|
||||
0, ~0, 1, RF_ACTIVE);
|
||||
if (sc->bar1res == NULL) {
|
||||
uprintf("Memory allocation of PCI base register 1 failed!\n");
|
||||
printf("Memory allocation of PCI base register 1 failed!\n");
|
||||
error = ENXIO;
|
||||
goto fail2;
|
||||
}
|
||||
|
@ -298,7 +293,7 @@ board_write(struct ni_softc *sc, uint16_t address, uint16_t value) {
|
|||
sc->irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &(sc->irqid),
|
||||
0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
|
||||
if (sc->irqres == NULL) {
|
||||
uprintf("IRQ allocation failed!\n");
|
||||
printf("IRQ allocation failed!\n");
|
||||
error = ENXIO;
|
||||
goto fail3;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue