Skip to content

Commit

Permalink
drm/nouveau/device: remove pci/platform_device from common struct
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
  • Loading branch information
Ben Skeggs committed Aug 28, 2015
1 parent c7af0ff commit 26c9e8e
Show file tree
Hide file tree
Showing 27 changed files with 106 additions and 108 deletions.
40 changes: 10 additions & 30 deletions drivers/gpu/drm/nouveau/include/nvkm/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ enum nvkm_devidx {
NVKM_ENGINE_SEC,
NVKM_ENGINE_MSPDEC,

NVKM_SUBDEV_NR,
NVKM_SUBDEV_NR
};

enum nvkm_device_type {
NVKM_DEVICE_PCI,
NVKM_DEVICE_AGP,
NVKM_DEVICE_PCIE,
NVKM_DEVICE_TEGRA,
};

struct nvkm_device {
const struct nvkm_device_func *func;
const struct nvkm_device_quirk *quirk;
struct device *dev;
enum nvkm_device_type type;
u64 handle;
const char *name;
const char *cfgopt;
Expand All @@ -63,9 +71,6 @@ struct nvkm_device {
struct mutex mutex;
int refcount;

struct pci_dev *pdev;
struct platform_device *platformdev;

void __iomem *pri;

struct nvkm_event event;
Expand Down Expand Up @@ -150,6 +155,7 @@ struct nvkm_device_func {
void (*fini)(struct nvkm_device *, bool suspend);
resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
bool cpu_coherent;
};

struct nvkm_device_quirk {
Expand Down Expand Up @@ -220,32 +226,6 @@ int nvkm_device_list(u64 *name, int size);
_temp; \
})

static inline bool
nv_device_is_pci(struct nvkm_device *device)
{
return device->pdev != NULL;
}

static inline bool
nv_device_is_cpu_coherent(struct nvkm_device *device)
{
return (!IS_ENABLED(CONFIG_ARM) && nv_device_is_pci(device));
}

static inline struct device *
nv_device_base(struct nvkm_device *device)
{
return nv_device_is_pci(device) ? &device->pdev->dev :
&device->platformdev->dev;
}

struct platform_device;

enum nv_bus_type {
NVKM_BUS_PCI,
NVKM_BUS_PLATFORM,
};

void nvkm_device_del(struct nvkm_device **);

struct nvkm_device_oclass {
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/nouveau/nouveau_abi16.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,19 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)
getparam->value = device->info.chipset;
break;
case NOUVEAU_GETPARAM_PCI_VENDOR:
if (nv_device_is_pci(nvxx_device(device)))
if (nvxx_device(device)->func->pci)
getparam->value = dev->pdev->vendor;
else
getparam->value = 0;
break;
case NOUVEAU_GETPARAM_PCI_DEVICE:
if (nv_device_is_pci(nvxx_device(device)))
if (nvxx_device(device)->func->pci)
getparam->value = dev->pdev->device;
else
getparam->value = 0;
break;
case NOUVEAU_GETPARAM_BUS_TYPE:
if (!nv_device_is_pci(nvxx_device(device)))
if (!nvxx_device(device)->func->pci)
getparam->value = 3;
else
if (drm_pci_device_is_agp(dev))
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/nouveau/nouveau_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
return len;
}

bool nouveau_acpi_rom_supported(struct pci_dev *pdev)
bool nouveau_acpi_rom_supported(struct device *dev)
{
acpi_status status;
acpi_handle dhandle, rom_handle;

dhandle = ACPI_HANDLE(&pdev->dev);
dhandle = ACPI_HANDLE(dev);
if (!dhandle)
return false;

Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/nouveau/nouveau_acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ void nouveau_register_dsm_handler(void);
void nouveau_unregister_dsm_handler(void);
void nouveau_switcheroo_optimus_dsm(void);
int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
bool nouveau_acpi_rom_supported(struct device *);
void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
#else
static inline bool nouveau_is_optimus(void) { return false; };
static inline bool nouveau_is_v1_dsm(void) { return false; };
static inline void nouveau_register_dsm_handler(void) {}
static inline void nouveau_unregister_dsm_handler(void) {}
static inline void nouveau_switcheroo_optimus_dsm(void) {}
static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
static inline bool nouveau_acpi_rom_supported(struct device *dev) { return false; }
static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
static inline void *nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return NULL; }
#endif
Expand Down
7 changes: 5 additions & 2 deletions drivers/gpu/drm/nouveau/nouveau_agp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "nouveau_agp.h"
#include "nouveau_reg.h"

#include <core/pci.h>

#if __OS_HAS_AGP
MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)");
static int nouveau_agpmode = -1;
Expand All @@ -28,6 +30,7 @@ static unsigned long
get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info)
{
struct nvif_device *device = &drm->device;
struct pci_dev *pdev = nvxx_device(device)->func->pci(nvxx_device(device))->pdev;
struct nouveau_agpmode_quirk *quirk = nouveau_agpmode_quirk_list;
int agpmode = nouveau_agpmode;
unsigned long mode = info->mode;
Expand All @@ -45,8 +48,8 @@ get_agp_mode(struct nouveau_drm *drm, const struct drm_agp_info *info)
while (agpmode == -1 && quirk->hostbridge_vendor) {
if (info->id_vendor == quirk->hostbridge_vendor &&
info->id_device == quirk->hostbridge_device &&
nvxx_device(device)->pdev->vendor == quirk->chip_vendor &&
nvxx_device(device)->pdev->device == quirk->chip_device) {
pdev->vendor == quirk->chip_vendor &&
pdev->device == quirk->chip_device) {
agpmode = quirk->mode;
NV_INFO(drm, "Forcing agp mode to %dX. Use agpmode to override.\n",
agpmode);
Expand Down
18 changes: 9 additions & 9 deletions drivers/gpu/drm/nouveau/nouveau_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
nvbo->tile_flags = tile_flags;
nvbo->bo.bdev = &drm->ttm.bdev;

if (!nv_device_is_cpu_coherent(nvxx_device(&drm->device)))
if (!nvxx_device(&drm->device)->func->cpu_coherent)
nvbo->force_coherent = flags & TTM_PL_FLAG_UNCACHED;

nvbo->page_shift = 12;
Expand Down Expand Up @@ -466,8 +466,8 @@ nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
return;

for (i = 0; i < ttm_dma->ttm.num_pages; i++)
dma_sync_single_for_device(nv_device_base(device),
ttm_dma->dma_address[i], PAGE_SIZE, DMA_TO_DEVICE);
dma_sync_single_for_device(device->dev, ttm_dma->dma_address[i],
PAGE_SIZE, DMA_TO_DEVICE);
}

void
Expand All @@ -486,8 +486,8 @@ nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
return;

for (i = 0; i < ttm_dma->ttm.num_pages; i++)
dma_sync_single_for_cpu(nv_device_base(device),
ttm_dma->dma_address[i], PAGE_SIZE, DMA_FROM_DEVICE);
dma_sync_single_for_cpu(device->dev, ttm_dma->dma_address[i],
PAGE_SIZE, DMA_FROM_DEVICE);
}

int
Expand Down Expand Up @@ -1487,13 +1487,13 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
drm = nouveau_bdev(ttm->bdev);
device = nvxx_device(&drm->device);
dev = drm->dev;
pdev = nv_device_base(device);
pdev = device->dev;

/*
* Objects matching this condition have been marked as force_coherent,
* so use the DMA API for them.
*/
if (!nv_device_is_cpu_coherent(device) &&
if (!nvxx_device(&drm->device)->func->cpu_coherent &&
ttm->caching_state == tt_uncached)
return ttm_dma_populate(ttm_dma, dev->dev);

Expand Down Expand Up @@ -1552,13 +1552,13 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
drm = nouveau_bdev(ttm->bdev);
device = nvxx_device(&drm->device);
dev = drm->dev;
pdev = nv_device_base(device);
pdev = device->dev;

/*
* Objects matching this condition have been marked as force_coherent,
* so use the DMA API for them.
*/
if (!nv_device_is_cpu_coherent(device) &&
if (!nvxx_device(&drm->device)->func->cpu_coherent &&
ttm->caching_state == tt_uncached) {
ttm_dma_unpopulate(ttm_dma, dev->dev);
return;
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/nouveau/nouveau_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ nouveau_sysfs_fini(struct drm_device *dev)
struct nvif_device *device = &drm->device;

if (sysfs && sysfs->ctrl.priv) {
device_remove_file(nv_device_base(nvxx_device(device)), &dev_attr_pstate);
device_remove_file(nvxx_device(device)->dev, &dev_attr_pstate);
nvif_object_fini(&sysfs->ctrl);
}

Expand All @@ -192,7 +192,7 @@ nouveau_sysfs_init(struct drm_device *dev)
NVIF_IOCTL_NEW_V0_CONTROL, NULL, 0,
&sysfs->ctrl);
if (ret == 0)
device_create_file(nv_device_base(nvxx_device(device)), &dev_attr_pstate);
device_create_file(nvxx_device(device)->dev, &dev_attr_pstate);

return 0;
}
2 changes: 1 addition & 1 deletion drivers/gpu/drm/nouveau/nouveau_ttm.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ nouveau_ttm_init(struct nouveau_drm *drm)
int ret;

bits = nvxx_mmu(&drm->device)->dma_bits;
if (nv_device_is_pci(nvxx_device(&drm->device))) {
if (nvxx_device(&drm->device)->func->pci) {
if (drm->agp.stat == ENABLED ||
!pci_dma_supported(dev->pdev, DMA_BIT_MASK(bits)))
bits = 32;
Expand Down
8 changes: 4 additions & 4 deletions drivers/gpu/drm/nouveau/nv50_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
nv50_chan_destroy(&dmac->base);

if (dmac->ptr) {
struct pci_dev *pdev = nvxx_device(device)->pdev;
pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
struct device *dev = nvxx_device(device)->dev;
dma_free_coherent(dev, PAGE_SIZE, dmac->ptr, dmac->handle);
}
}

Expand All @@ -226,8 +226,8 @@ nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,

mutex_init(&dmac->lock);

dmac->ptr = pci_alloc_consistent(nvxx_device(device)->pdev,
PAGE_SIZE, &dmac->handle);
dmac->ptr = dma_alloc_coherent(nvxx_device(device)->dev, PAGE_SIZE,
&dmac->handle, GFP_KERNEL);
if (!dmac->ptr)
return -ENOMEM;

Expand Down
14 changes: 3 additions & 11 deletions drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ nvkm_device_del(struct nvkm_device **pdevice)
int
nvkm_device_ctor(const struct nvkm_device_func *func,
const struct nvkm_device_quirk *quirk,
void *dev, enum nv_bus_type type, u64 handle,
struct device *dev, enum nvkm_device_type type, u64 handle,
const char *name, const char *cfg, const char *dbg,
bool detect, bool mmio, u64 subdev_mask,
struct nvkm_device *device)
Expand All @@ -2312,16 +2312,8 @@ nvkm_device_ctor(const struct nvkm_device_func *func,

device->func = func;
device->quirk = quirk;
switch (type) {
case NVKM_BUS_PCI:
device->pdev = dev;
device->dev = &device->pdev->dev;
break;
case NVKM_BUS_PLATFORM:
device->platformdev = dev;
device->dev = &device->platformdev->dev;
break;
}
device->dev = dev;
device->type = type;
device->handle = handle;
device->cfgopt = cfg;
device->dbgopt = dbg;
Expand Down
7 changes: 5 additions & 2 deletions drivers/gpu/drm/nouveau/nvkm/engine/device/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ nvkm_device_pci_func = {
.fini = nvkm_device_pci_fini,
.resource_addr = nvkm_device_pci_resource_addr,
.resource_size = nvkm_device_pci_resource_size,
.cpu_coherent = !IS_ENABLED(CONFIG_ARM),
};

int
Expand Down Expand Up @@ -1671,8 +1672,10 @@ nvkm_device_pci_new(struct pci_dev *pci_dev, const char *cfg, const char *dbg,
*pdevice = &pdev->device;
pdev->pdev = pci_dev;

return nvkm_device_ctor(&nvkm_device_pci_func, quirk,
pci_dev, NVKM_BUS_PCI,
return nvkm_device_ctor(&nvkm_device_pci_func, quirk, &pci_dev->dev,
pci_is_pcie(pci_dev) ? NVKM_DEVICE_PCIE :
pci_find_capability(pci_dev, PCI_CAP_ID_AGP) ?
NVKM_DEVICE_AGP : NVKM_DEVICE_PCI,
(u64)pci_domain_nr(pci_dev->bus) << 32 |
pci_dev->bus->number << 16 |
PCI_SLOT(pci_dev->devfn) << 8 |
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/nouveau/nvkm/engine/device/priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

int nvkm_device_ctor(const struct nvkm_device_func *,
const struct nvkm_device_quirk *,
void *, enum nv_bus_type type, u64 handle,
struct device *, enum nvkm_device_type, u64 handle,
const char *name, const char *cfg, const char *dbg,
bool detect, bool mmio, u64 subdev_mask,
struct nvkm_device *);
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ nvkm_device_tegra_func = {
.fini = nvkm_device_tegra_fini,
.resource_addr = nvkm_device_tegra_resource_addr,
.resource_size = nvkm_device_tegra_resource_size,
.cpu_coherent = false,
};

int
Expand All @@ -118,8 +119,8 @@ nvkm_device_tegra_new(struct platform_device *pdev,
tdev->pdev = pdev;
tdev->irq = -1;

return nvkm_device_ctor(&nvkm_device_tegra_func, NULL, pdev,
NVKM_BUS_PLATFORM, pdev->id, NULL,
return nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev,
NVKM_DEVICE_TEGRA, pdev->id, NULL,
cfg, dbg, detect, mmio, subdev_mask,
&tdev->device);
}
Expand Down
24 changes: 15 additions & 9 deletions drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,22 @@ nvkm_udevice_info(struct nvkm_udevice *udev, void *data, u32 size)
args->v0.platform = NV_DEVICE_INFO_V0_IGP;
break;
default:
if (device->pdev) {
if (pci_find_capability(device->pdev, PCI_CAP_ID_AGP))
args->v0.platform = NV_DEVICE_INFO_V0_AGP;
else
if (pci_is_pcie(device->pdev))
args->v0.platform = NV_DEVICE_INFO_V0_PCIE;
else
args->v0.platform = NV_DEVICE_INFO_V0_PCI;
} else {
switch (device->type) {
case NVKM_DEVICE_PCI:
args->v0.platform = NV_DEVICE_INFO_V0_PCI;
break;
case NVKM_DEVICE_AGP:
args->v0.platform = NV_DEVICE_INFO_V0_AGP;
break;
case NVKM_DEVICE_PCIE:
args->v0.platform = NV_DEVICE_INFO_V0_PCIE;
break;
case NVKM_DEVICE_TEGRA:
args->v0.platform = NV_DEVICE_INFO_V0_SOC;
break;
default:
WARN_ON(1);
break;
}
break;
}
Expand Down
Loading

0 comments on commit 26c9e8e

Please sign in to comment.