From patchwork Fri Dec 11 22:54:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 58312 Delivered-To: patch@linaro.org Received: by 10.112.73.68 with SMTP id j4csp176561lbv; Fri, 11 Dec 2015 15:05:50 -0800 (PST) X-Received: by 10.67.14.201 with SMTP id fi9mr28719089pad.41.1449875150417; Fri, 11 Dec 2015 15:05:50 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ra2si3948134pab.209.2015.12.11.15.05.50; Fri, 11 Dec 2015 15:05:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755415AbbLKXFs (ORCPT + 28 others); Fri, 11 Dec 2015 18:05:48 -0500 Received: from mail-bn1bon0063.outbound.protection.outlook.com ([157.56.111.63]:15683 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755350AbbLKXFp (ORCPT ); Fri, 11 Dec 2015 18:05:45 -0500 X-Greylist: delayed 108585 seconds by postgrey-1.27 at vger.kernel.org; Fri, 11 Dec 2015 18:05:45 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Suravee.Suthikulpanit@amd.com; Received: from ssuthiku-cz-dev.amd.com (165.204.77.1) by BY1PR12MB0438.namprd12.prod.outlook.com (10.162.147.14) with Microsoft SMTP Server (TLS) id 15.1.337.19; Fri, 11 Dec 2015 23:05:41 +0000 From: Suravee Suthikulpanit To: CC: , , Suravee Suthikulpanit Subject: [PATCH] iommu/amd: Assign default IOMMU when there is only one IOMMU Date: Fri, 11 Dec 2015 16:54:38 -0600 Message-ID: <1449874478-31770-1-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN1PR12CA0016.namprd12.prod.outlook.com (25.162.96.154) To BY1PR12MB0438.namprd12.prod.outlook.com (25.162.147.14) X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0438; 2:xdvh62/27sEVSPyTUWSeD9LQp2ZUeeuKqBzgn8ftafeUyuBFPvo2ie6JafqdoJd6NIt5Ii46DRcXjV/NTzuRNgJ6jFyexMKuiG0yKDa90fSLQaKF/FYuojP0ImCoKTW8P2YQoLWTfBDFkGES73+NUA==; 3:vQc2RopynOGzbUgcUjebAWsZa2yjkVJSFUyg+YNZ+fJCvo2KipgY+NFEO0hz1MFM5lnbKoh2s+sS4lC0UTpciXrZU6CTVIT0gCzD2+ccqT1vBbsI9pM3Z/x2VsgVpqqG; 25:A14r11166xkCj+YC1tpDL90fTTLK8p5mdK9SIeN8T4RijArc6YEJDXPrgHMWQv3D10+QM85VdM264E/4WXIVT0To18UcFuA3GTc37A20mQYMwTVSG0z/JBP2ctZmSz362nZWxd1jQGcx/12pB8aY2c+SpjdZrqi05kworWJsXNGn8rpECfvgExTZuE/NnlN/VxAwdf/ArwsO3HOVX6N0xhEK/kPuepurXq8F7WBZI0TP4lolFSbzEhrWWO+/U1DDwlvWmGE8Mfe8wZ3nVYX6lQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR12MB0438; X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0438; 20:+zOIDbs+RXHq1aBqQZrSDsATIFXB+Kg8RKwzp51RF7C070qhn5Q7OCVAwIpzEWlYJZgp4RwiPDW/VHQdYLJEa0HfNkbKsqNc1ozBZjsDcIe+ey9IsGdBzLhwehkY95eda1r+LsiuYC9NdOaM5dKReSTwcXniTFOXCi33Bn/ZnAdjGbGQOOyyfkxiqWuNjBjpeXR62kBPM11bD4JY8IgWMS/ytqHNn/qcJiyIld+BuFdePi4TWQUCef9ophEwT8r7KHLPXIdqfrd0uqRD9rKFn0pc5pO5nDHrFJZvbXhHQqYJsQxJ48UanJrDPsRoGuDdbvRtmp7hr2rgXJKp6hv+yDGOSsGRE0F0XUF28SvOBE73T4bot+I657kamZfgi2wNYveuzNcIsFaNL8GkJHL4QFpnV8n2QO952SLPJxc1ce75Ly6J56QgHgcFXFW7KBignRIA0zaaYWuIqoreO/s2jB8TThL2xfq3w4wdzIWgK/R6UH6VKk12B52UkIjJMToB; 4:Vb3XUuyURJQzreacy53/ztd6JFwXH+lyxoSmk2QtOV3NIiS/A7n+IopnsJU9buy6zZcEGPUl2MqDvHXxUYweWshIAsgKfL5M5sZhxwilJAKt70q923BUpcBNhj8olQIvqpA6GVPBekRwaK3yCqHHK/UyNKLClMd5gImtf/sh4OzzP/ekeRt7qqoOPg0lSNcznfPzcHV+dJ6ZevjO97d2meuelPPxO5tOClrxvUbaQKsr5vPL5iUCQWefP5PC+I4x/d9rpMqlj9r+Kt6nZwHJs5Qnvlrvlgr5AXKI/J2lKeHrYZeJVNjPzVgZBvJNkQhGlMeW06sQG0oPP2ISqbIPLmhl/PjwsI5wSW8jMfp4p1Z15OBT5nAyRmRV1i39AYo5/zySdI5py6YXjX2mlyGyBE9QcRBcnrjaAZRoVhfjzss= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(767451399110); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(3002001)(10201501046); SRVR:BY1PR12MB0438; BCL:0; PCL:0; RULEID:; SRVR:BY1PR12MB0438; X-Forefront-PRVS: 0787459938 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(189998001)(42186005)(122386002)(19580395003)(19580405001)(586003)(97736004)(110136002)(40100003)(92566002)(36756003)(53416004)(77096005)(50226001)(106356001)(105586002)(87976001)(66066001)(47776003)(5008740100001)(5003940100001)(50986999)(1096002)(6116002)(48376002)(3846002)(2351001)(229853001)(50466002)(101416001)(86362001)(5004730100002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR12MB0438; H:ssuthiku-cz-dev.amd.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0438; 23:yks4SNSdcalTZd9QUGU6cN5E0sPU5qxgVvNnXdb7kYtFNrDrYBnUf/k1PY4c2Ww7yVukZiaUUfTxt2tZwwxgDyt+KURyp9JNjBNsES418egA2EZYSXUNxw5tJlt3+Ng4Uf3sb/EM4VBLshLNbKIj3uQDzAG3w2YuC15Va0E8UCWXxWIWFPeBp0PpKBRi3gXo6C6sTVZ/jenn0rkHkcZm4JeyBnvuUvuIklyRqTV8t1bmz652FEeWeDmGuNUlNs4n1jfMTZTW/SatnkKkpUuKq9+4d3gkkUyCk0gq3us11XAPm8slPzB2yjAlEqxVE7a8BoekKjsUibUpjkGz2hEHy9h/FPStN14NqWMhjeKno7eb5sPA1uEGpH9AnLShkATREzFRjZBYVUUdc8dm5dKMuM0u2zVAA9RkMNup0R8tJ5Eu2TQYdd2Xt3AHLnKHtW5o0BI2lFu53kvCz9012qTrXeq+vIR5LWPbtKfmfnoIQCcWqwRIJy7Z/2tm1pWBevN3sMGryG5f9nrM0qbI3fsOTl10RlVmzNITQWd1lagQsvtfo5sExRJ9bV3y6B+umvav3vGPCrmKEICja2iwstkgXUf0XEo43GOFMuK+KyCUG/iXvzmh3zTpv/ormfwzRr/494lx0nkb16JUfSoyphBYqG+uaEqoB3BDaXfytdiohpnyCNwetFvVt2dJGugOAV9OJ9ZnYswHB0gJJ6tBlIMJCPZJ/yzgjrisOtS73uB/oPNifMDxHwYHsoTe4vPyMAcmtHAF2GppBoaOwpr+Pc6GzlsYKGgNLXK60eDMNB0BKKAVHC7UZ1JHVqhEfyt0LJklM7eLiPNgIXafjwkIJDxBys4r8DALkecFpqSn/zOcgjsvp+0V8fBa+58dRSy3+lQjijSXq548kWgkOZCeM3xNOMZLI6ZO2ekfNJmXBthQiBMKV6lxFss66wbRS0XsAclW X-Microsoft-Exchange-Diagnostics: 1; BY1PR12MB0438; 5:93UbytUkVrTIVs+l+BHivNu94AdO+RI2oVNiYW/vLPxqlpAGbByT6zrp2QSvb0sFD5jUSOjit8YsHh+3vGdKa1hLYtTZ2uYmw6ZDnXfAS7x45blbxgFe/QG4OHoQ+p4mX6r12Xbg5ynwlaJOVR1eiA==; 24:n6VOKNw5nudjskVurjkB0pFJHHK8sV6gtH46C63ww1NfqcsQA5ZZj9cJadp3fIZKwXWUCZOdCfpPg9rqbeXgUGYVxB5BjQx/5v3YYwtG7qo=; 20:ysQuSGZ3hzWeKgSKhrP8MvS/LbqKwxCTjvjv8H4gVQbjSa50o3sipqXeXIe7HDzVwWiW8c6XxDbls4aW6MLGn/7TMxjn4mU9PmqhwgOKig2XaT4g4H17UKAtQMwwJV01GRrRQ+QqtOPIywaENcc1c70A2HG8euVXQWiA0H4wnU0WeaAp1BWdsjqVeX1hpZdYqKL4iSXqrH24ex84OK290A2g+TAg92kGgJg9dEAQyX8LSe56SKzE48DPFifaQSz3 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2015 23:05:41.8804 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB0438 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current driver makes assumption that device with devid zero is always included in the range of devices to be managed by IOMMU. However, certain FW does not include devid zero in IVRS table. This has caused IOMMU perf driver to fail to initialize. This patch implements a workaround for this case by always assign devid zero to be handled by the first IOMMU. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu_init.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 013bdff..3bbad5c 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -656,6 +656,16 @@ static void __init set_iommu_for_device(struct amd_iommu *iommu, u16 devid) amd_iommu_rlookup_table[devid] = iommu; } +static struct amd_iommu *get_iommu_for_device(u16 devid) +{ + struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; + + /* Workaround: Always assign devid zero to the first IOMMU */ + if (!iommu && !devid && amd_iommus_present) + iommu = amd_iommus[0]; + return iommu; +} + /* * This function takes the device specific flags read from the ACPI * table and sets up the device table entry with that information @@ -751,7 +761,7 @@ static int __init add_early_maps(void) */ static void __init set_device_exclusion_range(u16 devid, struct ivmd_header *m) { - struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; + struct amd_iommu *iommu = get_iommu_for_device(devid); if (!(m->flags & IVMD_FLAG_EXCL_RANGE)) return; @@ -2255,7 +2265,7 @@ u8 amd_iommu_pc_get_max_banks(u16 devid) u8 ret = 0; /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; + iommu = get_iommu_for_device(devid); if (iommu) ret = iommu->max_banks; @@ -2275,7 +2285,7 @@ u8 amd_iommu_pc_get_max_counters(u16 devid) u8 ret = 0; /* locate the iommu governing the devid */ - iommu = amd_iommu_rlookup_table[devid]; + iommu = get_iommu_for_device(devid); if (iommu) ret = iommu->max_counters; @@ -2295,7 +2305,7 @@ int amd_iommu_pc_get_set_reg_val(u16 devid, u8 bank, u8 cntr, u8 fxn, return -ENODEV; /* Locate the iommu associated with the device ID */ - iommu = amd_iommu_rlookup_table[devid]; + iommu = get_iommu_for_device(devid); /* Check for valid iommu and pc register indexing */ if (WARN_ON((iommu == NULL) || (fxn > 0x28) || (fxn & 7)))