···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#define NV04_PFB_BOOT_0 0x001000002626+# define NV04_PFB_BOOT_0_RAM_AMOUNT 0x000000032727+# define NV04_PFB_BOOT_0_RAM_AMOUNT_32MB 0x000000002828+# define NV04_PFB_BOOT_0_RAM_AMOUNT_4MB 0x000000012929+# define NV04_PFB_BOOT_0_RAM_AMOUNT_8MB 0x000000023030+# define NV04_PFB_BOOT_0_RAM_AMOUNT_16MB 0x000000033131+# define NV04_PFB_BOOT_0_RAM_WIDTH_128 0x000000043232+# define NV04_PFB_BOOT_0_RAM_TYPE 0x000000283333+# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_8MBIT 0x000000003434+# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT 0x000000083535+# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT_4BANK 0x000000103636+# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_16MBIT 0x000000183737+# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBIT 0x000000203838+# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBITX16 0x000000283939+# define NV04_PFB_BOOT_0_UMA_ENABLE 0x000001004040+# define NV04_PFB_BOOT_0_UMA_SIZE 0x0000f0004141+4242+#include "priv.h"4343+4444+static int4545+nv04_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,4646+ struct nouveau_oclass *oclass, void *data, u32 size,4747+ struct nouveau_object **pobject)4848+{4949+ struct nouveau_fb *pfb = nouveau_fb(parent);5050+ struct nouveau_ram *ram;5151+ u32 boot0 = nv_rd32(pfb, NV04_PFB_BOOT_0);5252+ int ret;5353+5454+ ret = nouveau_ram_create(parent, engine, oclass, &ram);5555+ *pobject = nv_object(ram);5656+ if (ret)5757+ return ret;5858+5959+ if (boot0 & 0x00000100) {6060+ ram->size = ((boot0 >> 12) & 0xf) * 2 + 2;6161+ ram->size *= 1024 * 1024;6262+ } else {6363+ switch (boot0 & NV04_PFB_BOOT_0_RAM_AMOUNT) {6464+ case NV04_PFB_BOOT_0_RAM_AMOUNT_32MB:6565+ ram->size = 32 * 1024 * 1024;6666+ break;6767+ case NV04_PFB_BOOT_0_RAM_AMOUNT_16MB:6868+ ram->size = 16 * 1024 * 1024;6969+ break;7070+ case NV04_PFB_BOOT_0_RAM_AMOUNT_8MB:7171+ ram->size = 8 * 1024 * 1024;7272+ break;7373+ case NV04_PFB_BOOT_0_RAM_AMOUNT_4MB:7474+ ram->size = 4 * 1024 * 1024;7575+ break;7676+ }7777+ }7878+7979+ if ((boot0 & 0x00000038) <= 0x10)8080+ ram->type = NV_MEM_TYPE_SGRAM;8181+ else8282+ ram->type = NV_MEM_TYPE_SDRAM;8383+ return 0;8484+}8585+8686+struct nouveau_oclass8787+nv04_ram_oclass = {8888+ .handle = 0,8989+ .ofuncs = &(struct nouveau_ofuncs) {9090+ .ctor = nv04_ram_create,9191+ .dtor = _nouveau_ram_dtor,9292+ .init = _nouveau_ram_init,9393+ .fini = _nouveau_ram_fini,9494+ }9595+};
+61
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv10.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv10_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 cfg0 = nv_rd32(pfb, 0x100200);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ if (cfg0 & 0x00000001)4343+ ram->type = NV_MEM_TYPE_DDR1;4444+ else4545+ ram->type = NV_MEM_TYPE_SDRAM;4646+4747+ ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;4848+ return 0;4949+}5050+5151+5252+struct nouveau_oclass5353+nv10_ram_oclass = {5454+ .handle = 0,5555+ .ofuncs = &(struct nouveau_ofuncs) {5656+ .ctor = nv10_ram_create,5757+ .dtor = _nouveau_ram_dtor,5858+ .init = _nouveau_ram_init,5959+ .fini = _nouveau_ram_fini,6060+ }6161+};
+71
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv1a.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv1a_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ struct pci_dev *bridge;3535+ u32 mem, mib;3636+ int ret;3737+3838+ bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0, 1));3939+ if (!bridge) {4040+ nv_fatal(pfb, "no bridge device\n");4141+ return -ENODEV;4242+ }4343+4444+ ret = nouveau_ram_create(parent, engine, oclass, &ram);4545+ *pobject = nv_object(ram);4646+ if (ret)4747+ return ret;4848+4949+ if (nv_device(pfb)->chipset == 0x1a) {5050+ pci_read_config_dword(bridge, 0x7c, &mem);5151+ mib = ((mem >> 6) & 31) + 1;5252+ } else {5353+ pci_read_config_dword(bridge, 0x84, &mem);5454+ mib = ((mem >> 4) & 127) + 1;5555+ }5656+5757+ ram->type = NV_MEM_TYPE_STOLEN;5858+ ram->size = mib * 1024 * 1024;5959+ return 0;6060+}6161+6262+struct nouveau_oclass6363+nv1a_ram_oclass = {6464+ .handle = 0,6565+ .ofuncs = &(struct nouveau_ofuncs) {6666+ .ctor = nv1a_ram_create,6767+ .dtor = _nouveau_ram_dtor,6868+ .init = _nouveau_ram_init,6969+ .fini = _nouveau_ram_fini,7070+ }7171+};
+63
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv20.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv20_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 pbus1218 = nv_rd32(pfb, 0x001218);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ switch (pbus1218 & 0x00000300) {4343+ case 0x00000000: ram->type = NV_MEM_TYPE_SDRAM; break;4444+ case 0x00000100: ram->type = NV_MEM_TYPE_DDR1; break;4545+ case 0x00000200: ram->type = NV_MEM_TYPE_GDDR3; break;4646+ case 0x00000300: ram->type = NV_MEM_TYPE_GDDR2; break;4747+ }4848+ ram->size = (nv_rd32(pfb, 0x10020c) & 0xff000000);4949+ ram->parts = (nv_rd32(pfb, 0x100200) & 0x00000003) + 1;5050+ ram->tags = nv_rd32(pfb, 0x100320);5151+ return 0;5252+}5353+5454+struct nouveau_oclass5555+nv20_ram_oclass = {5656+ .handle = 0,5757+ .ofuncs = &(struct nouveau_ofuncs) {5858+ .ctor = nv20_ram_create,5959+ .dtor = _nouveau_ram_dtor,6060+ .init = _nouveau_ram_init,6161+ .fini = _nouveau_ram_fini,6262+ }6363+};
+65
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv40.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv40_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 pbus1218 = nv_rd32(pfb, 0x001218);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ switch (pbus1218 & 0x00000300) {4343+ case 0x00000000: ram->type = NV_MEM_TYPE_SDRAM; break;4444+ case 0x00000100: ram->type = NV_MEM_TYPE_DDR1; break;4545+ case 0x00000200: ram->type = NV_MEM_TYPE_GDDR3; break;4646+ case 0x00000300: ram->type = NV_MEM_TYPE_DDR2; break;4747+ }4848+4949+ ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;5050+ ram->parts = (nv_rd32(pfb, 0x100200) & 0x00000003) + 1;5151+ ram->tags = nv_rd32(pfb, 0x100320);5252+ return 0;5353+}5454+5555+5656+struct nouveau_oclass5757+nv40_ram_oclass = {5858+ .handle = 0,5959+ .ofuncs = &(struct nouveau_ofuncs) {6060+ .ctor = nv40_ram_create,6161+ .dtor = _nouveau_ram_dtor,6262+ .init = _nouveau_ram_init,6363+ .fini = _nouveau_ram_fini,6464+ }6565+};
+64
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv41.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv41_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 pfb474 = nv_rd32(pfb, 0x100474);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ if (pfb474 & 0x00000004)4343+ ram->type = NV_MEM_TYPE_GDDR3;4444+ if (pfb474 & 0x00000002)4545+ ram->type = NV_MEM_TYPE_DDR2;4646+ if (pfb474 & 0x00000001)4747+ ram->type = NV_MEM_TYPE_DDR1;4848+4949+ ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;5050+ ram->parts = (nv_rd32(pfb, 0x100200) & 0x00000003) + 1;5151+ ram->tags = nv_rd32(pfb, 0x100320);5252+ return 0;5353+}5454+5555+struct nouveau_oclass5656+nv41_ram_oclass = {5757+ .handle = 0,5858+ .ofuncs = &(struct nouveau_ofuncs) {5959+ .ctor = nv41_ram_create,6060+ .dtor = _nouveau_ram_dtor,6161+ .init = _nouveau_ram_init,6262+ .fini = _nouveau_ram_fini,6363+ }6464+};
+62
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv44.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv44_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 pfb474 = nv_rd32(pfb, 0x100474);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ if (pfb474 & 0x00000004)4343+ ram->type = NV_MEM_TYPE_GDDR3;4444+ if (pfb474 & 0x00000002)4545+ ram->type = NV_MEM_TYPE_DDR2;4646+ if (pfb474 & 0x00000001)4747+ ram->type = NV_MEM_TYPE_DDR1;4848+4949+ ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;5050+ return 0;5151+}5252+5353+struct nouveau_oclass5454+nv44_ram_oclass = {5555+ .handle = 0,5656+ .ofuncs = &(struct nouveau_ofuncs) {5757+ .ctor = nv44_ram_create,5858+ .dtor = _nouveau_ram_dtor,5959+ .init = _nouveau_ram_init,6060+ .fini = _nouveau_ram_fini,6161+ }6262+};
+64
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv49.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv49_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ u32 pfb914 = nv_rd32(pfb, 0x100914);3535+ int ret;3636+3737+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3838+ *pobject = nv_object(ram);3939+ if (ret)4040+ return ret;4141+4242+ switch (pfb914 & 0x00000003) {4343+ case 0x00000000: pfb->ram->type = NV_MEM_TYPE_DDR1; break;4444+ case 0x00000001: pfb->ram->type = NV_MEM_TYPE_DDR2; break;4545+ case 0x00000002: pfb->ram->type = NV_MEM_TYPE_GDDR3; break;4646+ case 0x00000003: break;4747+ }4848+4949+ pfb->ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;5050+ pfb->ram->parts = (nv_rd32(pfb, 0x100200) & 0x00000003) + 1;5151+ pfb->ram->tags = nv_rd32(pfb, 0x100320);5252+ return 0;5353+}5454+5555+struct nouveau_oclass5656+nv49_ram_oclass = {5757+ .handle = 0,5858+ .ofuncs = &(struct nouveau_ofuncs) {5959+ .ctor = nv49_ram_create,6060+ .dtor = _nouveau_ram_dtor,6161+ .init = _nouveau_ram_init,6262+ .fini = _nouveau_ram_fini,6363+ }6464+};
+55
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv4e.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include "priv.h"2626+2727+static int2828+nv4e_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,2929+ struct nouveau_oclass *oclass, void *data, u32 size,3030+ struct nouveau_object **pobject)3131+{3232+ struct nouveau_fb *pfb = nouveau_fb(parent);3333+ struct nouveau_ram *ram;3434+ int ret;3535+3636+ ret = nouveau_ram_create(parent, engine, oclass, &ram);3737+ *pobject = nv_object(ram);3838+ if (ret)3939+ return ret;4040+4141+ pfb->ram->size = nv_rd32(pfb, 0x10020c) & 0xff000000;4242+ pfb->ram->type = NV_MEM_TYPE_STOLEN;4343+ return 0;4444+}4545+4646+struct nouveau_oclass4747+nv4e_ram_oclass = {4848+ .handle = 0,4949+ .ofuncs = &(struct nouveau_ofuncs) {5050+ .ctor = nv4e_ram_create,5151+ .dtor = _nouveau_ram_dtor,5252+ .init = _nouveau_ram_init,5353+ .fini = _nouveau_ram_fini,5454+ }5555+};
+232
drivers/gpu/drm/nouveau/core/subdev/fb/ramnv50.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include <subdev/bios.h>2626+#include <core/mm.h>2727+#include "priv.h"2828+2929+void3030+nv50_ram_put(struct nouveau_fb *pfb, struct nouveau_mem **pmem)3131+{3232+ struct nouveau_mm_node *this;3333+ struct nouveau_mem *mem;3434+3535+ mem = *pmem;3636+ *pmem = NULL;3737+ if (unlikely(mem == NULL))3838+ return;3939+4040+ mutex_lock(&pfb->base.mutex);4141+ while (!list_empty(&mem->regions)) {4242+ this = list_first_entry(&mem->regions, typeof(*this), rl_entry);4343+4444+ list_del(&this->rl_entry);4545+ nouveau_mm_free(&pfb->vram, &this);4646+ }4747+4848+ nouveau_mm_free(&pfb->tags, &mem->tag);4949+ mutex_unlock(&pfb->base.mutex);5050+5151+ kfree(mem);5252+}5353+5454+static int5555+nv50_ram_get(struct nouveau_fb *pfb, u64 size, u32 align, u32 ncmin,5656+ u32 memtype, struct nouveau_mem **pmem)5757+{5858+ struct nouveau_mm *heap = &pfb->vram;5959+ struct nouveau_mm *tags = &pfb->tags;6060+ struct nouveau_mm_node *r;6161+ struct nouveau_mem *mem;6262+ int comp = (memtype & 0x300) >> 8;6363+ int type = (memtype & 0x07f);6464+ int back = (memtype & 0x800);6565+ int min, max, ret;6666+6767+ max = (size >> 12);6868+ min = ncmin ? (ncmin >> 12) : max;6969+ align >>= 12;7070+7171+ mem = kzalloc(sizeof(*mem), GFP_KERNEL);7272+ if (!mem)7373+ return -ENOMEM;7474+7575+ mutex_lock(&pfb->base.mutex);7676+ if (comp) {7777+ if (align == 16) {7878+ int n = (max >> 4) * comp;7979+8080+ ret = nouveau_mm_head(tags, 1, n, n, 1, &mem->tag);8181+ if (ret)8282+ mem->tag = NULL;8383+ }8484+8585+ if (unlikely(!mem->tag))8686+ comp = 0;8787+ }8888+8989+ INIT_LIST_HEAD(&mem->regions);9090+ mem->memtype = (comp << 7) | type;9191+ mem->size = max;9292+9393+ type = nv50_fb_memtype[type];9494+ do {9595+ if (back)9696+ ret = nouveau_mm_tail(heap, type, max, min, align, &r);9797+ else9898+ ret = nouveau_mm_head(heap, type, max, min, align, &r);9999+ if (ret) {100100+ mutex_unlock(&pfb->base.mutex);101101+ pfb->ram->put(pfb, &mem);102102+ return ret;103103+ }104104+105105+ list_add_tail(&r->rl_entry, &mem->regions);106106+ max -= r->length;107107+ } while (max);108108+ mutex_unlock(&pfb->base.mutex);109109+110110+ r = list_first_entry(&mem->regions, struct nouveau_mm_node, rl_entry);111111+ mem->offset = (u64)r->offset << 12;112112+ *pmem = mem;113113+ return 0;114114+}115115+116116+static u32117117+nv50_fb_vram_rblock(struct nouveau_fb *pfb, struct nouveau_ram *ram)118118+{119119+ int i, parts, colbits, rowbitsa, rowbitsb, banks;120120+ u64 rowsize, predicted;121121+ u32 r0, r4, rt, ru, rblock_size;122122+123123+ r0 = nv_rd32(pfb, 0x100200);124124+ r4 = nv_rd32(pfb, 0x100204);125125+ rt = nv_rd32(pfb, 0x100250);126126+ ru = nv_rd32(pfb, 0x001540);127127+ nv_debug(pfb, "memcfg 0x%08x 0x%08x 0x%08x 0x%08x\n", r0, r4, rt, ru);128128+129129+ for (i = 0, parts = 0; i < 8; i++) {130130+ if (ru & (0x00010000 << i))131131+ parts++;132132+ }133133+134134+ colbits = (r4 & 0x0000f000) >> 12;135135+ rowbitsa = ((r4 & 0x000f0000) >> 16) + 8;136136+ rowbitsb = ((r4 & 0x00f00000) >> 20) + 8;137137+ banks = 1 << (((r4 & 0x03000000) >> 24) + 2);138138+139139+ rowsize = parts * banks * (1 << colbits) * 8;140140+ predicted = rowsize << rowbitsa;141141+ if (r0 & 0x00000004)142142+ predicted += rowsize << rowbitsb;143143+144144+ if (predicted != ram->size) {145145+ nv_warn(pfb, "memory controller reports %d MiB VRAM\n",146146+ (u32)(ram->size >> 20));147147+ }148148+149149+ rblock_size = rowsize;150150+ if (rt & 1)151151+ rblock_size *= 3;152152+153153+ nv_debug(pfb, "rblock %d bytes\n", rblock_size);154154+ return rblock_size;155155+}156156+157157+static int158158+nv50_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,159159+ struct nouveau_oclass *oclass, void *data, u32 datasize,160160+ struct nouveau_object **pobject)161161+{162162+ struct nouveau_fb *pfb = nouveau_fb(parent);163163+ struct nouveau_device *device = nv_device(pfb);164164+ struct nouveau_bios *bios = nouveau_bios(device);165165+ struct nouveau_ram *ram;166166+ const u32 rsvd_head = ( 256 * 1024) >> 12; /* vga memory */167167+ const u32 rsvd_tail = (1024 * 1024) >> 12; /* vbios etc */168168+ u32 size;169169+ int ret;170170+171171+ ret = nouveau_ram_create(parent, engine, oclass, &ram);172172+ *pobject = nv_object(ram);173173+ if (ret)174174+ return ret;175175+176176+ ram->size = nv_rd32(pfb, 0x10020c);177177+ ram->size = (ram->size & 0xffffff00) |178178+ ((ram->size & 0x000000ff) << 32);179179+180180+ size = (ram->size >> 12) - rsvd_head - rsvd_tail;181181+ switch (device->chipset) {182182+ case 0xaa:183183+ case 0xac:184184+ case 0xaf: /* IGPs, no reordering, no real VRAM */185185+ ret = nouveau_mm_init(&pfb->vram, rsvd_head, size, 1);186186+ if (ret)187187+ return ret;188188+189189+ ram->type = NV_MEM_TYPE_STOLEN;190190+ ram->stolen = (u64)nv_rd32(pfb, 0x100e10) << 12;191191+ break;192192+ default:193193+ switch (nv_rd32(pfb, 0x100714) & 0x00000007) {194194+ case 0: ram->type = NV_MEM_TYPE_DDR1; break;195195+ case 1:196196+ if (nouveau_fb_bios_memtype(bios) == NV_MEM_TYPE_DDR3)197197+ ram->type = NV_MEM_TYPE_DDR3;198198+ else199199+ ram->type = NV_MEM_TYPE_DDR2;200200+ break;201201+ case 2: ram->type = NV_MEM_TYPE_GDDR3; break;202202+ case 3: ram->type = NV_MEM_TYPE_GDDR4; break;203203+ case 4: ram->type = NV_MEM_TYPE_GDDR5; break;204204+ default:205205+ break;206206+ }207207+208208+ ret = nouveau_mm_init(&pfb->vram, rsvd_head, size,209209+ nv50_fb_vram_rblock(pfb, ram) >> 12);210210+ if (ret)211211+ return ret;212212+213213+ ram->ranks = (nv_rd32(pfb, 0x100200) & 0x4) ? 2 : 1;214214+ ram->tags = nv_rd32(pfb, 0x100320);215215+ break;216216+ }217217+218218+ ram->get = nv50_ram_get;219219+ ram->put = nv50_ram_put;220220+ return 0;221221+}222222+223223+struct nouveau_oclass224224+nv50_ram_oclass = {225225+ .handle = 0,226226+ .ofuncs = &(struct nouveau_ofuncs) {227227+ .ctor = nv50_ram_create,228228+ .dtor = _nouveau_ram_dtor,229229+ .init = _nouveau_ram_init,230230+ .fini = _nouveau_ram_fini,231231+ }232232+};
+186
drivers/gpu/drm/nouveau/core/subdev/fb/ramnvc0.c
···11+/*22+ * Copyright 2013 Red Hat Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ * Authors: Ben Skeggs2323+ */2424+2525+#include <subdev/bios.h>2626+#include <subdev/ltcg.h>2727+2828+#include "priv.h"2929+3030+extern const u8 nvc0_pte_storage_type_map[256];3131+3232+void3333+nvc0_ram_put(struct nouveau_fb *pfb, struct nouveau_mem **pmem)3434+{3535+ struct nouveau_ltcg *ltcg = nouveau_ltcg(pfb);3636+3737+ if ((*pmem)->tag)3838+ ltcg->tags_free(ltcg, &(*pmem)->tag);3939+4040+ nv50_ram_put(pfb, pmem);4141+}4242+4343+int4444+nvc0_ram_get(struct nouveau_fb *pfb, u64 size, u32 align, u32 ncmin,4545+ u32 memtype, struct nouveau_mem **pmem)4646+{4747+ struct nouveau_mm *mm = &pfb->vram;4848+ struct nouveau_mm_node *r;4949+ struct nouveau_mem *mem;5050+ int type = (memtype & 0x0ff);5151+ int back = (memtype & 0x800);5252+ const bool comp = nvc0_pte_storage_type_map[type] != type;5353+ int ret;5454+5555+ size >>= 12;5656+ align >>= 12;5757+ ncmin >>= 12;5858+ if (!ncmin)5959+ ncmin = size;6060+6161+ mem = kzalloc(sizeof(*mem), GFP_KERNEL);6262+ if (!mem)6363+ return -ENOMEM;6464+6565+ INIT_LIST_HEAD(&mem->regions);6666+ mem->size = size;6767+6868+ mutex_lock(&pfb->base.mutex);6969+ if (comp) {7070+ struct nouveau_ltcg *ltcg = nouveau_ltcg(pfb);7171+7272+ /* compression only works with lpages */7373+ if (align == (1 << (17 - 12))) {7474+ int n = size >> 5;7575+ ltcg->tags_alloc(ltcg, n, &mem->tag);7676+ }7777+7878+ if (unlikely(!mem->tag))7979+ type = nvc0_pte_storage_type_map[type];8080+ }8181+ mem->memtype = type;8282+8383+ do {8484+ if (back)8585+ ret = nouveau_mm_tail(mm, 1, size, ncmin, align, &r);8686+ else8787+ ret = nouveau_mm_head(mm, 1, size, ncmin, align, &r);8888+ if (ret) {8989+ mutex_unlock(&pfb->base.mutex);9090+ pfb->ram->put(pfb, &mem);9191+ return ret;9292+ }9393+9494+ list_add_tail(&r->rl_entry, &mem->regions);9595+ size -= r->length;9696+ } while (size);9797+ mutex_unlock(&pfb->base.mutex);9898+9999+ r = list_first_entry(&mem->regions, struct nouveau_mm_node, rl_entry);100100+ mem->offset = (u64)r->offset << 12;101101+ *pmem = mem;102102+ return 0;103103+}104104+105105+static int106106+nvc0_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,107107+ struct nouveau_oclass *oclass, void *data, u32 size,108108+ struct nouveau_object **pobject)109109+{110110+ struct nouveau_fb *pfb = nouveau_fb(parent);111111+ struct nouveau_bios *bios = nouveau_bios(pfb);112112+ struct nouveau_ram *ram;113113+ const u32 rsvd_head = ( 256 * 1024) >> 12; /* vga memory */114114+ const u32 rsvd_tail = (1024 * 1024) >> 12; /* vbios etc */115115+ u32 parts = nv_rd32(pfb, 0x022438);116116+ u32 pmask = nv_rd32(pfb, 0x022554);117117+ u32 bsize = nv_rd32(pfb, 0x10f20c);118118+ u32 offset, length;119119+ bool uniform = true;120120+ int ret, part;121121+122122+ ret = nouveau_ram_create(parent, engine, oclass, &ram);123123+ *pobject = nv_object(ram);124124+ if (ret)125125+ return ret;126126+127127+ nv_debug(pfb, "0x100800: 0x%08x\n", nv_rd32(pfb, 0x100800));128128+ nv_debug(pfb, "parts 0x%08x mask 0x%08x\n", parts, pmask);129129+130130+ ram->type = nouveau_fb_bios_memtype(bios);131131+ ram->ranks = (nv_rd32(pfb, 0x10f200) & 0x00000004) ? 2 : 1;132132+133133+ /* read amount of vram attached to each memory controller */134134+ for (part = 0; part < parts; part++) {135135+ if (!(pmask & (1 << part))) {136136+ u32 psize = nv_rd32(pfb, 0x11020c + (part * 0x1000));137137+ if (psize != bsize) {138138+ if (psize < bsize)139139+ bsize = psize;140140+ uniform = false;141141+ }142142+143143+ nv_debug(pfb, "%d: mem_amount 0x%08x\n", part, psize);144144+ ram->size += (u64)psize << 20;145145+ }146146+ }147147+148148+ /* if all controllers have the same amount attached, there's no holes */149149+ if (uniform) {150150+ offset = rsvd_head;151151+ length = (ram->size >> 12) - rsvd_head - rsvd_tail;152152+ ret = nouveau_mm_init(&pfb->vram, offset, length, 1);153153+ } else {154154+ /* otherwise, address lowest common amount from 0GiB */155155+ ret = nouveau_mm_init(&pfb->vram, rsvd_head,156156+ (bsize << 8) * parts, 1);157157+ if (ret)158158+ return ret;159159+160160+ /* and the rest starting from (8GiB + common_size) */161161+ offset = (0x0200000000ULL >> 12) + (bsize << 8);162162+ length = (ram->size >> 12) - (bsize << 8) - rsvd_tail;163163+164164+ ret = nouveau_mm_init(&pfb->vram, offset, length, 0);165165+ if (ret)166166+ nouveau_mm_fini(&pfb->vram);167167+ }168168+169169+ if (ret)170170+ return ret;171171+172172+ ram->get = nvc0_ram_get;173173+ ram->put = nvc0_ram_put;174174+ return 0;175175+}176176+177177+struct nouveau_oclass178178+nvc0_ram_oclass = {179179+ .handle = 0,180180+ .ofuncs = &(struct nouveau_ofuncs) {181181+ .ctor = nvc0_ram_create,182182+ .dtor = _nouveau_ram_dtor,183183+ .init = _nouveau_ram_init,184184+ .fini = _nouveau_ram_fini,185185+ }186186+};