xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/pci/gf100.c (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
10a34fb31SBen Skeggs /*
20a34fb31SBen Skeggs  * Copyright 2015 Red Hat Inc.
30a34fb31SBen Skeggs  *
40a34fb31SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
50a34fb31SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
60a34fb31SBen Skeggs  * to deal in the Software without restriction, including without limitation
70a34fb31SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
80a34fb31SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
90a34fb31SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
100a34fb31SBen Skeggs  *
110a34fb31SBen Skeggs  * The above copyright notice and this permission notice shall be included in
120a34fb31SBen Skeggs  * all copies or substantial portions of the Software.
130a34fb31SBen Skeggs  *
140a34fb31SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150a34fb31SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
160a34fb31SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
170a34fb31SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
180a34fb31SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
190a34fb31SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
200a34fb31SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
210a34fb31SBen Skeggs  *
220a34fb31SBen Skeggs  * Authors: Ben Skeggs <bskeggs@redhat.com>
230a34fb31SBen Skeggs  */
240a34fb31SBen Skeggs #include "priv.h"
250a34fb31SBen Skeggs 
260a34fb31SBen Skeggs static void
gf100_pci_msi_rearm(struct nvkm_pci * pci)270a34fb31SBen Skeggs gf100_pci_msi_rearm(struct nvkm_pci *pci)
280a34fb31SBen Skeggs {
290a34fb31SBen Skeggs 	nvkm_pci_wr08(pci, 0x0704, 0xff);
300a34fb31SBen Skeggs }
310a34fb31SBen Skeggs 
327c923844SKarol Herbst void
gf100_pcie_set_version(struct nvkm_pci * pci,u8 ver)337c923844SKarol Herbst gf100_pcie_set_version(struct nvkm_pci *pci, u8 ver)
347c923844SKarol Herbst {
357c923844SKarol Herbst 	struct nvkm_device *device = pci->subdev.device;
367c923844SKarol Herbst 	nvkm_mask(device, 0x02241c, 0x1, ver > 1 ? 1 : 0);
377c923844SKarol Herbst }
387c923844SKarol Herbst 
397c923844SKarol Herbst int
gf100_pcie_version(struct nvkm_pci * pci)407c923844SKarol Herbst gf100_pcie_version(struct nvkm_pci *pci)
417c923844SKarol Herbst {
427c923844SKarol Herbst 	struct nvkm_device *device = pci->subdev.device;
437c923844SKarol Herbst 	return (nvkm_rd32(device, 0x02241c) & 0x1) + 1;
447c923844SKarol Herbst }
457c923844SKarol Herbst 
467c923844SKarol Herbst void
gf100_pcie_set_cap_speed(struct nvkm_pci * pci,bool full_speed)477c923844SKarol Herbst gf100_pcie_set_cap_speed(struct nvkm_pci *pci, bool full_speed)
487c923844SKarol Herbst {
497c923844SKarol Herbst 	struct nvkm_device *device = pci->subdev.device;
507c923844SKarol Herbst 	nvkm_mask(device, 0x02241c, 0x80, full_speed ? 0x80 : 0x0);
517c923844SKarol Herbst }
527c923844SKarol Herbst 
537c923844SKarol Herbst int
gf100_pcie_cap_speed(struct nvkm_pci * pci)547c923844SKarol Herbst gf100_pcie_cap_speed(struct nvkm_pci *pci)
557c923844SKarol Herbst {
567c923844SKarol Herbst 	struct nvkm_device *device = pci->subdev.device;
577c923844SKarol Herbst 	u8 punits_pci_cap_speed = nvkm_rd32(device, 0x02241c) & 0x80;
587c923844SKarol Herbst 	if (punits_pci_cap_speed == 0x80)
597c923844SKarol Herbst 		return 1;
607c923844SKarol Herbst 	return 0;
617c923844SKarol Herbst }
627c923844SKarol Herbst 
637c923844SKarol Herbst int
gf100_pcie_init(struct nvkm_pci * pci)647c923844SKarol Herbst gf100_pcie_init(struct nvkm_pci *pci)
657c923844SKarol Herbst {
667c923844SKarol Herbst 	bool full_speed = g84_pcie_cur_speed(pci) == NVKM_PCIE_SPEED_5_0;
677c923844SKarol Herbst 	gf100_pcie_set_cap_speed(pci, full_speed);
687c923844SKarol Herbst 	return 0;
697c923844SKarol Herbst }
707c923844SKarol Herbst 
717c923844SKarol Herbst int
gf100_pcie_set_link(struct nvkm_pci * pci,enum nvkm_pcie_speed speed,u8 width)727c923844SKarol Herbst gf100_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width)
737c923844SKarol Herbst {
747c923844SKarol Herbst 	gf100_pcie_set_cap_speed(pci, speed == NVKM_PCIE_SPEED_5_0);
757c923844SKarol Herbst 	g84_pcie_set_link_speed(pci, speed);
767c923844SKarol Herbst 	return 0;
777c923844SKarol Herbst }
787c923844SKarol Herbst 
790a34fb31SBen Skeggs static const struct nvkm_pci_func
800a34fb31SBen Skeggs gf100_pci_func = {
815d5b43f5SPierre Moreau 	.init = g84_pci_init,
820a34fb31SBen Skeggs 	.rd32 = nv40_pci_rd32,
830a34fb31SBen Skeggs 	.wr08 = nv40_pci_wr08,
840a34fb31SBen Skeggs 	.wr32 = nv40_pci_wr32,
850a34fb31SBen Skeggs 	.msi_rearm = gf100_pci_msi_rearm,
867c923844SKarol Herbst 
877c923844SKarol Herbst 	.pcie.init = gf100_pcie_init,
887c923844SKarol Herbst 	.pcie.set_link = gf100_pcie_set_link,
897c923844SKarol Herbst 
907c923844SKarol Herbst 	.pcie.max_speed = g84_pcie_max_speed,
917c923844SKarol Herbst 	.pcie.cur_speed = g84_pcie_cur_speed,
927c923844SKarol Herbst 
937c923844SKarol Herbst 	.pcie.set_version = gf100_pcie_set_version,
947c923844SKarol Herbst 	.pcie.version = gf100_pcie_version,
95725af748SKarol Herbst 	.pcie.version_supported = g92_pcie_version_supported,
960a34fb31SBen Skeggs };
970a34fb31SBen Skeggs 
980a34fb31SBen Skeggs int
gf100_pci_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_pci ** ppci)99*9b70cd54SBen Skeggs gf100_pci_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
100*9b70cd54SBen Skeggs 	      struct nvkm_pci **ppci)
1010a34fb31SBen Skeggs {
102*9b70cd54SBen Skeggs 	return nvkm_pci_new_(&gf100_pci_func, device, type, inst, ppci);
1030a34fb31SBen Skeggs }
104