diff --git a/bsd-core/Makefile b/bsd-core/Makefile index db563a6..d3463f0 100644 --- a/bsd-core/Makefile +++ b/bsd-core/Makefile @@ -18,6 +18,25 @@ SHAREDFILES= drm.h \ mga_state.c \ mga_ucode.h \ mga_warp.c \ + nouveau_drm.h \ + nouveau_drv.h \ + nouveau_fifo.c \ + nouveau_irq.c \ + nouveau_mem.c \ + nouveau_object.c \ + nouveau_reg.h \ + nouveau_state.c \ + nv04_fb.c \ + nv04_graph.c \ + nv04_mc.c \ + nv04_timer.c \ + nv10_fb.c \ + nv10_graph.c \ + nv20_graph.c \ + nv30_graph.c \ + nv40_fb.c \ + nv40_graph.c \ + nv40_mc.c \ r128_cce.c \ r128_drm.h \ r128_drv.h \ @@ -55,7 +74,7 @@ SHAREDFILES= drm.h \ via_verifier.h \ via_video.c -SUBDIR = drm mach64 mga r128 radeon savage sis tdfx i915 # via +SUBDIR = drm mach64 mga nouveau r128 radeon savage sis tdfx i915 # via CLEANFILES+= ${SHAREDFILES} diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h index 9ebb12a..a3044d9 100644 --- a/bsd-core/drmP.h +++ b/bsd-core/drmP.h @@ -1024,5 +1024,20 @@ static __inline__ void drm_core_dropmap(struct drm_map *map) { } +/* Inline function to read from PCI config space */ +static __inline__ void drm_pci_read_config_dword(struct drm_device *dev, int where, uint32_t *val) +{ +#if defined(__FreeBSD__) + *(val) = pci_read_config(dev->device, where, 4); +#elif defined(__NetBSD__) || defined(__OpenBSD__) + /*FIXME: this should go into the drm_device structure to avoid overhead*/ + pcitag_t pcitag; + pci_chipset_tag_t chipset_tag = dev->pa->pa_pc; + pcitag = pci_make_tag(chipset_tag, dev->pci_bus, dev->pci_slot, dev->pci_func); + + *(val) = (uint32_t)pci_conf_read(chipset_tag, pcitag, where); +#endif +} + #endif /* __KERNEL__ */ #endif /* _DRM_P_H_ */ diff --git a/bsd-core/nouveau/Makefile b/bsd-core/nouveau/Makefile new file mode 100644 index 0000000..12cf6dc --- /dev/null +++ b/bsd-core/nouveau/Makefile @@ -0,0 +1,25 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/.. +KMOD= nouveau +NO_MAN= YES +SRCS= nouveau_drv.c nouveau_fifo.c nouveau_irq.c nouveau_mem.c nouveau_object.c nouveau_state.c \ + nv04_fb.c nv04_graph.c nv04_mc.c nv04_timer.c nv10_fb.c nv10_graph.c nv20_graph.c \ + nv30_graph.c nv40_fb.c nv40_graph.c nv40_mc.c +SRCS+= device_if.h bus_if.h pci_if.h opt_drm.h +CFLAGS+= -I. -I.. -Wno-unused + +.if defined(DRM_DEBUG) +DRM_DEBUG_OPT= "\#define DRM_DEBUG 1" +.endif + +.if !defined(DRM_NOLINUX) +DRM_LINUX_OPT= "\#define DRM_LINUX 1" +.endif + +opt_drm.h: + touch opt_drm.h + echo $(DRM_DEBUG_OPT) >> opt_drm.h + echo $(DRM_LINUX_OPT) >> opt_drm.h + +.include diff --git a/bsd-core/nouveau_drv.c b/bsd-core/nouveau_drv.c new file mode 100644 index 0000000..9a4bfa4 --- /dev/null +++ b/bsd-core/nouveau_drv.c @@ -0,0 +1,114 @@ +/* + * Copyright 2007 Alexander Eichner. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/* mga_drv.c was used as template for this */ + +#include "drmP.h" +#include "drm.h" +#include "nouveau_drv.h" + +#include "drm_pciids.h" + +static drm_pci_id_list_t pciidlist[] = { + nouveau_PCI_IDS +}; + +extern drm_ioctl_desc_t nouveau_ioctls[]; +extern int nouveau_max_ioctl; + +static void nouveau_configure(drm_device_t *dev) +{ + dev->driver.firstopen = nouveau_firstopen; + dev->driver.load = nouveau_load; + dev->driver.unload = nouveau_unload; + dev->driver.lastclose = nouveau_lastclose; + dev->driver.irq_preinstall = nouveau_irq_preinstall; + dev->driver.irq_postinstall = nouveau_irq_postinstall; + dev->driver.irq_uninstall = nouveau_irq_uninstall; + dev->driver.irq_handler = nouveau_irq_handler; + + dev->driver.ioctls = nouveau_ioctls; + dev->driver.max_ioctl = nouveau_max_ioctl; + + dev->driver.name = DRIVER_NAME; + dev->driver.desc = DRIVER_DESC; + dev->driver.date = DRIVER_DATE; + dev->driver.major = DRIVER_MAJOR; + dev->driver.minor = DRIVER_MINOR; + dev->driver.patchlevel = DRIVER_PATCHLEVEL; + + dev->driver.use_agp = 1; + dev->driver.use_sg = 1; + dev->driver.use_pci_dma = 1; + dev->driver.use_irq = 1; +} + +#ifdef __FreeBSD__ +static int +nouveau_probe(device_t dev) +{ + return drm_probe(dev, pciidlist); +} + +static int +nouveau_attach(device_t nbdev) +{ + drm_device_t *dev = device_get_softc(nbdev); + + bzero(dev, sizeof(drm_device_t)); + nouveau_configure(dev); + return drm_attach(nbdev, pciidlist); +} + +static device_method_t nouveau_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, nouveau_probe), + DEVMETHOD(device_attach, nouveau_attach), + DEVMETHOD(device_detach, drm_detach), + + { 0, 0 } +}; + +static driver_t nouveau_driver = { + "drm", + nouveau_methods, + sizeof(drm_device_t) +}; + +extern devclass_t drm_devclass; +#if __FreeBSD_version >= 700010 +DRIVER_MODULE(nouveau, vgapci, nouveau_driver, drm_devclass, 0, 0); +#else +DRIVER_MODULE(nouveau, pci, nouveau_driver, drm_devclass, 0, 0); +#endif +MODULE_DEPEND(nouveau, drm, 1, 1, 1); + +#elif defined(__NetBSD__) || defined(__OpenBSD__) +#ifdef _LKM +CFDRIVER_DECL(nouveau, DV_TTY, NULL); +#else +CFATTACH_DECL(nouveau, sizeof(drm_device_t), drm_probe, drm_attach, drm_detach, + drm_activate); +#endif +#endif diff --git a/linux-core/drmP.h b/linux-core/drmP.h index d879c2a..bab0d74 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -1271,6 +1271,9 @@ static inline void drm_ctl_free(void *pt, size_t size, int area) drm_free_memctl(size); } +/* function to read from config space */ +#define drm_pci_read_config_dword(dev, where, val) pci_read_config_dword(dev->pdev , where, val); + /*@}*/ #endif /* __KERNEL__ */ diff --git a/shared-core/nouveau_fifo.c b/shared-core/nouveau_fifo.c index 92166ee..1807423 100644 --- a/shared-core/nouveau_fifo.c +++ b/shared-core/nouveau_fifo.c @@ -327,6 +327,7 @@ static void nouveau_nv30_context_init(drm_device_t *dev, int channel) RAMFC_WR(SEMAPHORE, NV_READ(NV10_PFIFO_CACHE1_SEMAPHORE)); } +#if 0 static void nouveau_nv10_context_save(drm_device_t *dev) { drm_nouveau_private_t *dev_priv = dev->dev_private; @@ -350,6 +351,7 @@ static void nouveau_nv10_context_save(drm_device_t *dev) RAMFC_WR(SEMAPHORE , NV_READ(NV10_PFIFO_CACHE1_SEMAPHORE)); RAMFC_WR(DMA_SUBROUTINE , NV_READ(NV10_PFIFO_CACHE1_DMA_SUBROUTINE)); } +#endif #undef RAMFC_WR #define RAMFC_WR(offset, val) NV_WRITE(fifoctx + NV40_RAMFC_##offset, (val)) @@ -381,6 +383,7 @@ static void nouveau_nv40_context_init(drm_device_t *dev, int channel) RAMFC_WR(DMA_TIMESLICE , 0x0001FFFF); } +#if 0 static void nouveau_nv40_context_save(drm_device_t *dev) { drm_nouveau_private_t *dev_priv = dev->dev_private; @@ -408,6 +411,7 @@ static void nouveau_nv40_context_save(drm_device_t *dev) RAMFC_WR(DMA_TIMESLICE , NV_READ(NV04_PFIFO_DMA_TIMESLICE) & 0x1FFFF); RAMFC_WR(UNK_40 , NV_READ(NV40_PFIFO_UNK32E4)); } +#endif #undef RAMFC_WR /* This function should load values from RAMFC into PFIFO, but for now diff --git a/shared-core/nouveau_mem.c b/shared-core/nouveau_mem.c index 541f154..e655086 100644 --- a/shared-core/nouveau_mem.c +++ b/shared-core/nouveau_mem.c @@ -257,11 +257,11 @@ uint64_t nouveau_mem_fb_amount(struct drm_device *dev) // XXX won't work on BSD because of pci_read_config_dword if (dev_priv->flags&NV_NFORCE) { uint32_t mem; - pci_read_config_dword(dev->pdev, 0x7C, &mem); + drm_pci_read_config_dword(dev, 0x7C, &mem); return (uint64_t)(((mem >> 6) & 31) + 1)*1024*1024; } else if(dev_priv->flags&NV_NFORCE2) { uint32_t mem; - pci_read_config_dword(dev->pdev, 0x84, &mem); + drm_pci_read_config_dword(dev, 0x84, &mem); return (uint64_t)(((mem >> 4) & 127) + 1)*1024*1024; } else { uint64_t mem; @@ -391,8 +391,13 @@ struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint6 /* * Keep alloc size a multiple of the page size to keep drm_addmap() happy */ +#ifdef __linux__ if (size & (~PAGE_MASK)) size = ((size/PAGE_SIZE) + 1) * PAGE_SIZE; +#else /* BSD */ + if (size & PAGE_MASK) + size = ((size/PAGE_SIZE) + 1) * PAGE_SIZE; +#endif if (flags&NOUVEAU_MEM_AGP) { type=NOUVEAU_MEM_AGP; diff --git a/shared-core/nouveau_state.c b/shared-core/nouveau_state.c index e7930b9..9aad9ad 100644 --- a/shared-core/nouveau_state.c +++ b/shared-core/nouveau_state.c @@ -235,7 +235,7 @@ int nouveau_firstopen(struct drm_device *dev) int nouveau_load(struct drm_device *dev, unsigned long flags) { drm_nouveau_private_t *dev_priv; - int ret; + /*int ret;*/ if (flags==NV_UNKNOWN) return DRM_ERR(EINVAL); @@ -273,7 +273,7 @@ void nouveau_lastclose(struct drm_device *dev) int nouveau_unload(struct drm_device *dev) { - drm_free(dev->dev_private, sizeof(*dev->dev_private), DRM_MEM_DRIVER); + drm_free(dev->dev_private, sizeof(drm_nouveau_private_t), DRM_MEM_DRIVER); dev->dev_private = NULL; return 0; }